AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String
题目连接:
http://codeforces.com/contest/624/problem/C
Description
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
G has exactly n vertices, numbered from 1 to n.
For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.
Input
The first line of the input contains two integers n and m — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
Output
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.
Sample Input
2 1
1 2
Sample Output
Yes
aa
Hint
题意
给你一个图,然后让你给这些图标号,问你有没有一个合法的标号
标号就只能标a,b,c。
然后a会和ab连边,b和abc都连边,c和bc连边
有解就任意输出一个就好
题解:
我们首先把那种边集有n-1的点染成b,然后再随便选一个没有染成b的点当成a,然后和a连边的就是a,没有和a连边的就是c
扫一遍就可以确认所有点的颜色,最后再n^2check一发就好了
代码
#include<bits/stdc++.h>
using namespace std;
int mp[520][520];
int cnt[520];
int flag[520];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=1;
mp[y][x]=1;
cnt[x]++;
cnt[y]++;
}
for(int i=1;i<=n;i++)
if(cnt[i]==n-1)
flag[i]=2;
int now=0;
for(int i=1;i<=n;i++)
if(flag[i]!=2)
{
now=i;
break;
}
if(now==0)
{
printf("Yes\n");
for(int i=1;i<=n;i++)
cout<<"b";
cout<<endl;
return 0;
}
flag[now]=1;
for(int i=1;i<=n;i++)
{
if(now==i)continue;
if(!mp[i][now])flag[i]=3;
else if(flag[i]==0)flag[i]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)continue;
if(mp[i][j])
{
if(abs(flag[j]-flag[i])>1)
return puts("No");
}
else
{
if(abs(flag[j]-flag[i])<=1)
return puts("No");
}
}
}
printf("Yes\n");
for(int i=1;i<=n;i++)
if(flag[i]==1)printf("a");
else if(flag[i]==2)printf("b");
else printf("c");
printf("\n");
}
AIM Tech Round (Div. 2) C. Graph and String 二分图染色的更多相关文章
- 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 ...
- AIM Tech Round (Div. 2) B. Making a String 贪心
B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round (Div. 1) D. Birthday 数学 暴力
D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- AIM Tech Round (Div. 2) A. Save Luke 水题
A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...
- AIM Tech Round (Div. 2) B
B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- AIM Tech Round (Div. 2) A
A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AIM Tech Round (Div. 1) C. Electric Charges 二分
C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...
随机推荐
- Jquery图片随滚动条加载
很久以前的写的Jquery图片随滚动条加载,现在不是什么新技术,应用也很广泛,大大提高图片多的页面打开速度! 有需要的朋友看看吧!有什么意见或建议欢迎留言交流! Demo.html 源码: < ...
- MFC类目录及头文件(转)
类 描述 头文件 CAnimateCtrl 自动化通用控件 afxcmn.h CArchive afx.h CArchiveException afx.h CArray afxtempl.h CAsy ...
- 转 Flash与PS交互动画
FLASH是可以点击体验的,不是图片哦. UI中国不能上传flash,但是站酷可以,UI中国的就下载载附件看看吧 本人学生党兼网页设计师菜鸟一名,因为无聊练习做了个FLASH的交互 所以很多学弟学妹们 ...
- Flex的基础用法【转】
//获得屏幕的分辨率 var x:Number=Capabilities.screenResolutionX; var y:Number=Capabilities.screenResolutionY; ...
- php 解压 .gz 文件
在百度搜索到的 PharData 类和 ZipArchive 都是解压不了 .gz 的文件的,后来在 google 搜索到解决方法,问题解决. try { $phar = new PharData($ ...
- 【Hadoop代码笔记】Hadoop作业提交之Job初始化
一.概要描述 在上一篇博文中主要描述了JobTracker和其几个服务(或功能)模块的接收到提交的job后的一些处理.其中很重要的一部分就作业的初始化.因为代码片段图的表达问题,本应该在上篇描述的内容 ...
- 【JSON】JSON字符串的操作(不断积累中)
一.JS遍历JSON串 示例01 目标:返回的JSON串中,一个Key对应的Value是一个数组(若在Java程序中,是一个List). 现在要求获取每个数组中的第一个对象元素中的name属性的值. ...
- HDU 4612 Warm up(2013多校2 1002 双连通分量)
Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Su ...
- python知识点(07-08)
python: 循环else: while true: if x>1: print() break else: print() 文件循环: for line in open(‘test.txt’ ...
- SQL嵌套查寻初识,以及SOME ANY EXISTS的基础常识
定义: 1 .指在一个外层查询中包含有另一个内层查询.其中外层查询称为主查询,内层查询称为子查询. 2 .SQL允许多层嵌套,由内而外地进行分析,子查询的结果作为主查询的查询条件 3 .子查询中一般不 ...