Graph and String
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
2 1
1 2
output
Yes
aa
input
4 3
1 2
1 3
1 4
output
No
Note

In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.

In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.

  这题特别容易错!!!!!!!!!

  颠覆了我的人生观!!!!!!!!

  我的OI之路啊!!!!!!!!!!

  

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int G[][];
int n,m;
int ans[];
bool Solve(int node)
{
bool ok=true;
for(int i=;i<=n;i++)
if(G[node][i]){
if(ans[i]){
if(ans[node]==ans[i])return false;
}
else
ans[i]=-ans[node],ok&=Solve(i);
}
return ok;
}
void print()
{
printf("Yes\n");
for(int i=;i<=n;i++)
printf("%c",'b'+ans[i]);
printf("\n");
}
int main()
{
scanf("%d%d",&n,&m);
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(i!=j)
G[i][j]=;
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
G[x][y]=;
G[y][x]=;
} int flag=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(G[i][j]&&!ans[i]){
ans[i]=;
if(!Solve(i))
flag=;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(!G[i][j]&&(ans[i]-ans[j]==||ans[i]-ans[j]==-)){
flag=;
}
if(flag)
print();
else
puts("No"); return ;
}

图论:(Code Forces) Graph and String的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

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

  4. Error Code: 1630. FUNCTION rand.string does not exist

    1.错误描述 13:50:13 call new_procedure Error Code: 1630. FUNCTION rand.string does not exist. Check the ...

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

  6. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  7. codeforces 624C Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  9. Code Forces 26C Dijkstra?

    C. Dijkstra? time limit per test 1 second memory limit per test 64 megabytes input standard input ou ...

随机推荐

  1. 查询可用的Nuget服务地址

    解决访问Nuget源失败问题 查询IP址址 nslookup nuget.org 如失败,通过google 的dns服务器查询 nslookup nuget.org 8.8.8.8 将得到的Ip地址加 ...

  2. Android Animation学习 实现 IOS 滤镜退出动画

    IOS的用户体验做的很好,其中一点很重要的地方就是动画效果. 最近在学习Android的Animation,简单实现了一个IOS相机滤镜退出的动画: 布局文件:activity_animation_d ...

  3. Android中Cursor类的概念和用法

    http://blog.sina.com.cn/s/blog_618199e60101fskp.html 使用过 SQLite数据库的童鞋对 Cursor 应该不陌生,加深自己和大家对Android ...

  4. C# 数字证书微信API调用使用参考事例

    X.509 v.3 证书的方法.一个比较完整的调用  微信  API的示例: private stringGetResponseResult()         { string strRespons ...

  5. oracle约束条件状态

    Oracle完整性约束有一下4种: • DISABLE NOVALIDATE • ENABLE NOVALIDATE • DISABLE VALIDATE • ENABLE VALIDATE   •  ...

  6. 【转】iOS-Core-Animation-Advanced-Techniques(一)

     图层树.寄宿图以及图层几何学(一)图层的树状结构 巨妖有图层,洋葱也有图层,你有吗?我们都有图层 -- 史莱克 原文:http://www.cocoachina.com/ios/20150104/1 ...

  7. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

  8. OpenCV中Mat的详解

    每次碰到Mat都得反复查具体的用法,网上的基础讲解不多,难得看到一篇,赶快转来收藏~ 原文地址:http://www.opencvchina.com/thread-1039-1-1.html 目标 我 ...

  9. SGU 159.Self-Replicating Numbers

    时间限制:0.5s 空间限制:6M 题意:         在b(2<b<36)进制中,找到所有长度为n(0<n<2000)的自守数k,满足k^2%b^n=k,字典序输出.   ...

  10. html5本地数据库(一)

    本地数据库 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important ...