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

Sample test(s)
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.

看了半天才看明白题意,可以理解为给n个点涂色(可涂的颜色有a,b,c),相连接的点可以涂aa bb cc ab ba bc cb。

问是否存在可行的涂色方案,有的话 输出。

样例2的话他解释的很清晰了

这么连的话 3 4也得连接。与样例描述不符。

思路:类似于贪心,如果某个点连接了其他n-1个点,那么这个点就被标记为b。然后再找一个没有被标记的点,标记成a.同时与a相连接的点也标记成a。剩下那些没有被标记的点标记成c.然后n^2 检查一遍是否成立。

/* ***********************************************
Author :guanjun
Created Time :2016/2/5 19:01:28
File Name :cfAIMc.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; bool cmp(int a,int b){
return a>b;
}
int mark[];
int vis[][];
int cnt[];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,m,x,y;
while(cin>>n>>m){
cle(vis);
cle(cnt);
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
vis[x][y]=vis[y][x]=;
cnt[x]++;
cnt[y]++;
}
cle(mark);
for(int i=;i<=n;i++){
if(cnt[i]==n-){
mark[i]=;//b
}
}
for(int i=;i<=n;i++){
if(!mark[i]){
mark[i]=;//a
for(int j=;j<=n;j++){
if(mark[j]!=&&vis[i][j])mark[j]=;
}
break;
}
}
for(int i=;i<=n;i++){
if(!mark[i])mark[i]=;//c
}
int flag=;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(vis[i][j]){
//if(!mark[i]||!mark[j])flag=1;
if((mark[i]+mark[j]==)&&(mark[i]!=mark[j]))flag=;
//if(flag)break;
}
else{
if(!mark[i]&&!mark[j])continue;
if(!((mark[i]+mark[j]==)&&(mark[i]!=mark[j])))flag=; }
if(flag)break;
}
if(flag)break;
}
if(flag)puts("No");
else{
puts("Yes");
for(int i=;i<=n;i++){
printf("%c",mark[i]-+'a');
}
}
}
return ;
}

最新文章

  1. Azure底层架构的初步分析
  2. SQL Server SQL性能优化之--数据库在“简单”参数化模式下,自动参数化SQL带来的问题
  3. Linux系统下的程序开发之:命名规范
  4. R语言排序:sort(),rank(),order()示例
  5. 2016.8.16 HTML5重要标签及其属性学习
  6. git如何使用 svn如何使用
  7. &lt;meta http-equiv=&quot;refresh&quot; content=&quot;0; url=&quot;&gt;是什么意思?
  8. Spark系列—01 Spark集群的安装
  9. [转]ubuntu14.04安装好用的google拼音输入法
  10. Ubuntu下SVN命令行递归加入文件夹文件(免去一个一个的加入 --force)
  11. wxpython tab切换页面
  12. 关于使用mybatis的几点总结
  13. 关于VC++中virtual ~的含义
  14. 全面盘点当前Android后台保活方案的真实运行效果(截止2019年前)
  15. python数学库math模块
  16. script nGrinder_TestRunnerInsertMysqlSingle.groovy
  17. Windows Server 2008 双网卡 断网问题 总结
  18. dedecms调用日期格式化形式大全
  19. FileWriter剖析
  20. CentOS 7下安装Python3.5

热门文章

  1. 刷题总结——table(ssoi)
  2. json-lib maven依赖出错的问题
  3. Laravel 报500错误
  4. linux网络性能评估
  5. 有向图最小路径覆盖方法浅析、证明 //hdu 3861
  6. CentOS 7.5 初始网络配置
  7. linux find grep 查找命令
  8. iOS 读书笔记 第一章
  9. esrichina
  10. 浅谈Heatmap