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.如果两个点之间有边,那么他们之间的差 ...
随机推荐
- 10 steps to becoming the developer everyone wants
You thought it was all about programming skills. But you were wrong! Great code is fine, yet command ...
- 转15个必须知道的chrome开发者技巧GIF
在Web开发者中,Google Chrome是使用最广泛的浏览器.六周一次的发布周期和一套强大的不断扩大开发功能,使其成为了web开发者必备的工具.你可能已经熟悉了它的部分功能,如使用console和 ...
- JavaScript 中 for in 循环和数组的问题
本文由 伯乐在线 - ElvisKang 翻译,进林 校稿.未经许可,禁止转载!英文出处:adripofjavascript.com.欢迎加入翻译小组. JavaScript的for…in循环用于迭代 ...
- .net中SessionState相关配置
web.config关于sessionState节点的配置方案,sessionState有四种模式:off,inProc,StateServer,SqlServer. 1.off模式 从字面上就可 ...
- centos安装配置nginx
1.安装gcc yum install gcc 2.安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思) yum install -y pcre pcre-devel ...
- Microsoft.ReportViewer.WebForms, Version=10.0.0.0的报错问题,解决方案
未能加载文件或程序集,或者web.config报错! 已解决:直接找到(默认在 路径/Microsoft Visual Studio 8/ReportViewer).把里面的3个DLL传上去就OK了! ...
- POJ 1456 Supermarket 区间问题并查集||贪心
F - Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- HDOJ 1870
#include<stdio.h> #include<stack> #include<string.h> #include<iostream> usin ...
- BADIP filter
#!/bin/bash touch /tmp/badipnew.log;touch /tmp/newip.log; if [ ! -f "/tmp/badip.log" ];the ...
- 一段功能齐全的PHP常用重定向代码html+js+header
/** * 重定向浏览器到指定的 URL * * @param string $url 要重定向的 url * @param int $delay 等待多少秒以后跳转 * @param bool $j ...