C. Graph and String
二分图染色
b点跟除自身外所有的点连接,共n-1个,首先把连接n-1个的点全部设为b点,其它点任意一点设为a,与a相连的都是a点,剩余为c点。最后验证是否成立。
验证条件为,所有连接的点之间的差值的绝对值不超过1,未连接的点之间的差值的绝对值都大于1.
#include<bits/stdc++.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int mp[][];
int cnt[];
int flag[];
int n,m;
int main()
{
scanf("%d%d",&n,&m); for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=mp[y][x]=;
cnt[x]++;
cnt[y]++;
}
for(int i=;i<=n;i++)
{
if(cnt[i]==n-)
flag[i]=; }
int now=;
for(int i=;i<=n;i++)
{
if(flag[i]!=)
{
now=i;
break;
}
}
if(now==)
{
printf("Yes\n");
for(int i=;i<=n;i++)
printf("b");
return ;
} flag[now]=;
for(int i=;i<=n;i++)
{
if(now==i) continue;
// if(mp[i][now])
if(!mp[i][now]) flag[i]=;
else if(flag[i]==) flag[i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j) continue;
if(mp[i][j])
{
if(abs(flag[i]-flag[j])>)
return puts("No");
}
else
{
if(abs(flag[i]-flag[j])<=)
return puts("No");
}
}
}
printf("Yes\n");
for(int i=;i<=n;i++)
{
if(flag[i]==) cout<<'a';
else if(flag[i]==) cout<<'b';
else cout<<'c';
}
return ; }
C. Graph and String的更多相关文章
- AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...
- 图论:(Code Forces) Graph and String
Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- AIM Tech Round (Div. 2) C. Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 624C Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 623A. Graph and String 构造
题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...
- 【CodeForces 624C】Graph and String
题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...
- cf623A. Graph and String(二分图 构造)
题意 题目链接 Sol 可以这样考虑,在原图中没有边相连的点的值肯定是a / c 那么直接二分图染色即可 #include<bits/stdc++.h> #define LL long l ...
- [Codeforces 623A] Graph and String
[题目链接] http://codeforces.com/contest/623/problem/A [算法] 首先 , 所有与其他节点都有连边的节点需标号为'b' 然后 , 我们任选一个节点 , 将 ...
- 【Henu ACM Round#16 C】Graph and String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 根据题意:先明确以下规则: 1.如果两个点之间没有边,那么这两个点只能是a或c,且不能相同 2.如果两个点之间有边,那么他们之间的差 ...
随机推荐
- 微信内置浏览器的 User Agent的判断
如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是: Mozilla/5.0 (iPhone; CPU ...
- ReactJS入门学习一
ReactJS入门学习一 阅读目录 React是什么? React如何制作组件? 理解组件属性props 理解页面中如何渲染数据的 理解从服务器端获取数据及理解state的 回到顶部 React是什么 ...
- 对target="framename"的理解(实现分页的demo)
先上图,说明一下我主要想实现什么功能. 一.演示图 演示首页: 演示内容页(包括按钮切换页+模板内容页): 演示首页到演示内容页的一个演变过程:
- 基于 MeanShift 算法的目标跟踪问题研究
参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/15/2398769.html MeanShift 算法作为一种基于特征的跟踪方法,基本思想 ...
- 算法训练 Torry的困惑
问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突然想到一个问题,前10.100.1000.10000……个质数的乘积是多少呢?他把这个问题告诉老师 ...
- FFT(1)
FFT Complex struct complex{ double re,im; complex(double r,double i){re=r,im=i;} complex(){re=0.0,im ...
- Nginx图片剪裁模块探究 http_image_filter_module
官方地址:http://nginx.org/en/docs/http/ngx_http_image_filter_module.html 煮酒品茶:前半部安装和官方说明,后半部分实践 #yum ins ...
- C/C++程序终止时执行的函数——atexit()函数详解
很多时候我们需要在程序退出的时候做一些诸如释放资源的操作,但程序退出的方式有很多种,比如main()函数运行结束.在程序的某个地方用exit()结束程序.用户通过Ctrl+C或Ctrl+break操作 ...
- Django authentication 使用方法
转自 : https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
- 【UGUI】Canvas和Rect Transform
Canvas 1.所有的UI元件都需要放在Canvas里 2.UI元件的绘制顺序,与在 Hierarchy的顺序相同,在上面的元素会先被绘制,位于后续绘制元素的下面 3.可以选择3种不同的渲染模式: ...