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.如果两个点之间有边,那么他们之间的差 ...
随机推荐
- delete this及堆破坏检测方法
作者: Bruce 日期: 2012年06月03日 04:20 周日 发表评论 (0) 查看评论 --END*1--> 0 条评论 --END*2-->1,837 人阅读 程序BU ...
- javascript模板方法模式
一:什么是模板方法模式: 模板方法模式由二部分组成,第一部分是抽象父类,第二部分是具体实现的子类,一般的情况下是抽象父类封装了子类的算法框架,包括实现一些公共方法及封装子类中所有方法的执行顺序,子类可 ...
- 小白科普之JavaScript的数组
一.与其他语言数据的比较 相同点:有序列表 不同点:js的数组的每一项可以保存任何类型的数据:数组的大小是可以动态调整的 二.数组创建的两种方法 1) var colors = new ...
- 添加删除虚拟ip
添加 ip -f inet addr add 192.168.1.245/32 brd 192.168.1.245 dev ens32 删除 ip -f inet addr del 192.168 ...
- Public and Private Interfaces in ruby
Your latest client is a bank, and they’ve tasked you with requiring customers to enter their passwor ...
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- PHP使用CURL上传|下载文件
CURL下载文件 /** * @param string $img_url 下载文件地址 * @param string $save_path 下载文件保存目录 * @param string $fi ...
- mysql数据库性能优化(包括SQL,表结构,索引,缓存)
优化目标减少 IO 次数IO永远是数据库最容易瓶颈的地方,这是由数据库的职责所决定的,大部分数据库操作中超过90%的时间都是 IO 操作所占用的,减少 IO 次数是 SQL 优化中需要第一优先考虑,当 ...
- HDOJ 1864 最大报销额(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1864 最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memor ...
- SPFA算法心得
SPFA算法是改进后的Bellman-Ford算法,只是速度更快,而且作为一个算法,它更容易理解和编写,甚至比Dijkstra和B-F更易读(当然,Floyd是另一回事了,再也没有比Floyd还好写的 ...