博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AIM Tech Round (Div. 2) C. Graph and String
阅读量:4331 次
发布时间:2019-06-06

本文共 4591 字,大约阅读时间需要 15 分钟。

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        :guanjunCreated Time  :2016/2/5 19:01:28File Name     :cfAIMc.cpp************************************************ */#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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 << 61;const double eps=1e-5;using namespace std;bool cmp(int a,int b){ return a>b;}int mark[600];int vis[510][510];int cnt[600];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=1;i<=m;i++){ scanf("%d%d",&x,&y); vis[x][y]=vis[y][x]=1; cnt[x]++; cnt[y]++; } cle(mark); for(int i=1;i<=n;i++){ if(cnt[i]==n-1){ mark[i]=2;//b } } for(int i=1;i<=n;i++){ if(!mark[i]){ mark[i]=1;//a for(int j=1;j<=n;j++){ if(mark[j]!=2&&vis[i][j])mark[j]=1; } break; } } for(int i=1;i<=n;i++){ if(!mark[i])mark[i]=3;//c } int flag=0; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(vis[i][j]){ //if(!mark[i]||!mark[j])flag=1; if((mark[i]+mark[j]==4)&&(mark[i]!=mark[j]))flag=1; //if(flag)break; } else{ if(!mark[i]&&!mark[j])continue; if(!((mark[i]+mark[j]==4)&&(mark[i]!=mark[j])))flag=1; } if(flag)break; } if(flag)break; } if(flag)puts("No"); else{ puts("Yes"); for(int i=1;i<=n;i++){ printf("%c",mark[i]-1+'a'); } } } return 0;}

 

转载于:https://www.cnblogs.com/pk28/p/5196708.html

你可能感兴趣的文章
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
linux下wc命令详解
查看>>
敏捷开发中软件测试团队的职责和产出是什么?
查看>>
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>
阶段3 2.Spring_02.程序间耦合_5 编写工厂类和配置文件
查看>>
阶段3 2.Spring_01.Spring框架简介_05.spring的优势
查看>>