C. Graph and String
二分图染色
b点跟除自身外所有的点连接,共n-1个,首先把连接n-1个的点全部设为b点,其它点任意一点设为a,与a相连的都是a点,剩余为c点。最后验证是否成立。
验证条件为,所有连接的点之间的差值的绝对值不超过1,未连接的点之间的差值的绝对值都大于1.
#include<bits/stdc++.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int mp[][];
int cnt[];
int flag[];
int n,m;
int main()
{
scanf("%d%d",&n,&m); for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=mp[y][x]=;
cnt[x]++;
cnt[y]++;
}
for(int i=;i<=n;i++)
{
if(cnt[i]==n-)
flag[i]=; }
int now=;
for(int i=;i<=n;i++)
{
if(flag[i]!=)
{
now=i;
break;
}
}
if(now==)
{
printf("Yes\n");
for(int i=;i<=n;i++)
printf("b");
return ;
} flag[now]=;
for(int i=;i<=n;i++)
{
if(now==i) continue;
// if(mp[i][now])
if(!mp[i][now]) flag[i]=;
else if(flag[i]==) flag[i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j) continue;
if(mp[i][j])
{
if(abs(flag[i]-flag[j])>)
return puts("No");
}
else
{
if(abs(flag[i]-flag[j])<=)
return puts("No");
}
}
}
printf("Yes\n");
for(int i=;i<=n;i++)
{
if(flag[i]==) cout<<'a';
else if(flag[i]==) cout<<'b';
else cout<<'c';
}
return ; }
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 ...
- 图论:(Code Forces) Graph and String
Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 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 ...
- codeforces 624C Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 623A. Graph and String 构造
题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...
- 【CodeForces 624C】Graph and String
题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...
- cf623A. Graph and String(二分图 构造)
题意 题目链接 Sol 可以这样考虑,在原图中没有边相连的点的值肯定是a / c 那么直接二分图染色即可 #include<bits/stdc++.h> #define LL long l ...
- [Codeforces 623A] Graph and String
[题目链接] http://codeforces.com/contest/623/problem/A [算法] 首先 , 所有与其他节点都有连边的节点需标号为'b' 然后 , 我们任选一个节点 , 将 ...
- 【Henu ACM Round#16 C】Graph and String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 根据题意:先明确以下规则: 1.如果两个点之间没有边,那么这两个点只能是a或c,且不能相同 2.如果两个点之间有边,那么他们之间的差 ...
随机推荐
- Linux的一个暴力破解工具九头蛇hydra
首先还是书写本文的 参考档:http://www.cnblogs.com/mchina/archive/2013/01/01/2840815.html 工具介绍:原文为官方英文解释本人给翻译下 数量最 ...
- CSS简写指南
高效的css写法中的一条就是使用简写.通过简写可以让你的CSS文件更小,更易读.而了解CSS属性简写也是前端开发工程师的基本功之一.今天我们系统地总结一下CSS属性的缩写. 色彩缩写 色彩的缩写最简单 ...
- 入门必看--JavaScript基础
JavaScript他是一种描述性语言,其实他并不难学,只要用心学,一定会学好,我相信大家在看这篇文章的时候,一定也学过HTML吧,使用JavaScript就是为了能和网页有更好的交互,下面切入主题. ...
- Intent的Flag
小段代码: Intent it=new Intent(); it.setClass(Setting.this,Main.class);//从Setting跳转到Main it.addFlags(Int ...
- Ubuntu 下 LAMP 的配置文件路径 转:
配置文件路径: 1>apache 的配置文件路径 /etc/apache2/apache2.conf 2>apache 网站字符编码配置路径 /etc/apache2/conf.d/c ...
- POJ 1308&&HDU 1272 并查集判断图
HDU 1272 I - 小希的迷宫 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- python 异步线程简单实现
import threading def foo(): with open(r'./result.log','wb') as f: f.write('=some logs here ==') t = ...
- Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- PYTHON实现HTTP摘要认证(DIGEST AUTHENTICATION)
参考: http://blog.csdn.net/kiwi_coder/article/details/28677651 http://blog.csdn.net/gl1987807/article/ ...
- poj3904
题意:给出n(n<10000)个数,这些数<=10000,要求选出四个数字且他们的最大公约数为1的(注意:不需要两两互质),有多少种选法. 分析: 容斥原理 假设平面上有一些圆,互相之间有 ...