AIM Tech Round (Div. 2) C. Graph and String
2 seconds
256 megabytes
standard input
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.
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.
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.
- 2 1
1 2
- Yes
aa
- 4 3
1 2
1 3
1 4
- No
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 ;
- }
AIM Tech Round (Div. 2) C. Graph and String的更多相关文章
- 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 ...
- 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 ...
随机推荐
- idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...
- uva 11762 数学期望+记忆化搜索
题目大意:给一个正整数N,每次可以在不超过N的素数中随机选择一个P,如果P是N的约数,则把N变成N/p,否则N不变,问平均情况下需要多少次随机选择,才能把N变成1? 分析:根据数学期望的线性和全期望公 ...
- K大数查询(bzoj 3110)
Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置 ...
- unity的List构造函数在IOS平台存在缺陷
当迩使用一个int[]或者string[]类似的数组时,以数组来初始化List对象,有可能在IOS平台上会出现初始化对象为空,比如 , }; List<int> listTest = ne ...
- js判断手机的横竖屏调整样式
在移动端,我们经常遇到横竖屏的问题,所以我们改如何判断或针对横竖屏来写代码呢.首先需要在head中加入如下代码: <meta name="viewport" content= ...
- 洛谷 P1710 地铁涨价
题目背景 本题开O2优化,请注意常数 题目描述 博艾市除了有海底高铁连接中国大陆.台湾与日本,市区里也有很成熟的轨道交通系统.我们可以认为博艾地铁系统是一个无向连通图.博艾有N个地铁站,同时有M小段地 ...
- 微信公众账户的开发者模式(一) 部分细节access_token的获取等
十四老久没有写博客了,中间经历了,事业,感情的几分波折.现在终于稍微缓过来一点.又是一次从头开始,走在匆忙的路上. 好了煽情完了,直接上代码了. 基础就不说了我用的是vs2005开发的,部署在iis6 ...
- Info.plist 的字段解释
bundle字段 这些字段名都是XML中的名称,在xcode的属性编辑器中,名字并不相同 bundle目录中的属性列表详细描述了有关该bundle的信息.Finder和一些系统API在一些情况下会使用 ...
- iOS数据持久化存储
本文中的代码托管在github上:https://github.com/WindyShade/DataSaveMethods 相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每 ...
- Go -- 漫谈IM通信架构
前前后后做的IM和推送系统已经有好几个了,一直都想好好总结下,因此就有了这篇文章.在我刚学编程的那会儿,觉得网络通信是一个很牛逼和门槛很高的一门技术,但是随着开源技术的发展和互联网知识的共享,现在要写 ...