AIM Tech Round (Div. 2) C. Graph and String 二分图染色
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 二分图染色的更多相关文章
- 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 ...
- 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 ...
随机推荐
- php-LAMP试题
ylbtech-doc:php-LAMP试题 LAMP试题 1.A,LAMP试题返回顶部 1.{PHP LAMP题目}变量$email的值是字符串 user@example.com ,以下哪项能把字符 ...
- Web 通信 之 长连接、长轮询(long polling)(转)
基于HTTP的长连接,是一种通过长轮询方式实现"服务器推"的技术,它弥补了HTTP简单的请求应答模式的不足,极大地增强了程序的实时性和交互性. 一.什么是长连接.长轮询? 用通俗易 ...
- Android百度地图开发(二)地图覆盖物
上一篇文章写道如何在一个mapview中简单的显示地图:本次学习一下如何在地图上添加一些覆盖物. 1.设置显示交通地图: // 显示交通地图 mapView.setTraffic(true); 2.设 ...
- unity3d Human skin real time rendering 真实模拟人皮实时渲染(转)
先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成 ...
- 【LeetCode】169 - Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 捣蛋phpwind过滤器执行流程
从上一篇我们就大概就知道过滤器的定义和怎样去配置,这一节来说说执行流程 public function run($handlerAdapter = null) { $handlerAdapter != ...
- centos6.3 安装配置redis
1.下载安装 1.1 下载包 注:在http://download.redis.io/releases查询需要下载的版本 wget http://download.redis.io/releases/ ...
- linux nginx安装(转载)
1.linux 下面安装 1.下载 pcre-8.10.tar.gz nginx-1.1.1.tar.gz 2.安装 pcre 让nginx支持rewrite pcre-8.10.tar.gz 上 ...
- linux库文件编写入门(笔记)
linux库文件的编写 作者: laomai地址: http://blog.csdn.net/laomai 本文主要参考了如下资料⑴hcj写的"Linux静态/动态链接库的创建和使用&quo ...
- mongodb地理空间索引原理阅读摘要
http://www.cnblogs.com/taoweiji/p/3710495.html 具体原理在上面 简单概述,(x,y)经纬度坐标,通过geohash的方式,通过N次方块四分割生成一个坐标码 ...