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 二分图染色的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  4. AIM Tech Round (Div. 1) D. Birthday 数学 暴力

    D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...

  5. 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 ...

  6. AIM Tech Round (Div. 2) A. Save Luke 水题

    A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...

  7. 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 ...

  8. 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 ...

  9. AIM Tech Round (Div. 1) C. Electric Charges 二分

    C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...

随机推荐

  1. VB6.0编程笔记——(2)开发环境准备&学习前导入

    工欲善其事必先利其器,着手开始学习写代码之前,我们需要先准备好需要用到的工具.这篇文章会教大家部署好环境,同时会告知前期我们需要知道的一点内容(可以不用特别理解,只要记住用法就行,后续会深入展开介绍) ...

  2. <测试用例设计>用户及权限管理功能常规测试方法

    1)  赋予一个人员相应的权限后,在界面上看此人员是否具有此权限,并以此人员身份登陆,验证权限设置是否正确(能否超出所给予的权限): 2)  删除或修改已经登陆系统并正在进行操作的人员的权限,程序能否 ...

  3. ps制作哈7海报字体

    模仿也需要较强的功底和分析思路.如下面的教程,作者模仿的是电影海报字.文字构造虽不复杂,不过思路不对的话就容易走弯路.最终效果 1.先来分析文字的构造,大致由两部分组成,一部分是浮雕字,另一部分是质感 ...

  4. MVC linq To SQL更新数据库操作

    首先在视图中提交数据,使用Html.BeginForm() @using(Html.BeginForm()) { @Html.EditorForModel() //编辑模板.控制器中传过来的数据 &l ...

  5. mysql error: Access denied for user 'root'@'localhost' (using password: YES)

    昨天重装了下系统,安装好mysql后,安装了客户端工具连接mysql,提示Access denied for user 'root'@'localhost' (using password: YES) ...

  6. BITED程序员语言学习心得之:C#语言基础

    一.HelloWorld 我们先来看看最简单的C#代码——HelloWorld: using System; using System.Collections.Generic; using Syste ...

  7. 2013年19个最棒的HTML5网站模板免费下载

    上次我们整理了14个HTML5奉献给大家下载了,今天我再给大家整理了19个2013最新的HTML5模板供有需要的朋友下载使用,它们涉及不同的行业的模板需求,支持手机设备,十分精美! 1. Affini ...

  8. 浅谈w3c标准

    #浅谈w3c标准 ##w3c标准是什么 w3c标准包括多个方面,官方是从应用角度分的,相关的文档可以戳[这里](http://www.w3.org/standards/).如果从WEB技术角度,可以分 ...

  9. 挖坟之Spring.NET IOC容器初始化

    因查找ht项目中一个久未解决spring内部异常,翻了一段时间源码.以此文总结springIOC,容器初始化过程. 语言背景是C#.网上有一些基于java的spring源码分析文档,大而乱,乱而不全, ...

  10. c++声明与定义

    c++声明与定义 声明是将一个名称引入程序.定义提供了一个实体在程序中的唯一描述.声明和定义有时是同时存在的. 如 int  a; extern int b=1; 只有当extern中不存在初始化才是 ...