codeforces 623A. Graph and String 构造
给出一个图, 每个节点只有三种情况, a,b, c。 a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环。给出初始的连边情况, 判断这个图是否满足条件。
由题意可以推出来b必然和其他的n-1个点都有连边, 所以初始将度数为n-1的点全都编号为b。 然后任选一个与b相连且无编号的点, 编号为1. 然后所有与1无连边的点都是3.
然后O(n^2)检查一下是否合理。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[], b[], de[], c[];
int mp[][];
int main()
{
int n, m, pos = ;
cin>>n>>m;
for(int i = ; i<m; i++) {
scanf("%d%d", &a[i], &b[i]);
de[a[i]]++, de[b[i]]++;
mp[a[i]][b[i]] = mp[b[i]][a[i]] = ;
}
for(int i = ; i<=n; i++) {
if(de[i] == n-) {
c[i] = ;
}
}
for(int i = ; i<=n; i++) {
if(!c[i]) {
pos = i;
c[i] = ;
break;
}
}
if(!pos) {
puts("Yes");
for(int i = ; i<n; i++)
cout<<'b';
return ;
}
for(int i = ; i<=n; i++) {
if(i == pos)
continue;
if(!mp[i][pos])
c[i] = ;
else if(!c[i])
c[i] = ;
}
int flag = ;
for(int i = ; i<=n; i++) {
for(int j = i+; j<=n; j++) {
if(abs(c[i]-c[j])>&&mp[i][j]) {
flag = ;
}
if(abs(c[i]-c[j])<= && !mp[i][j]) {
flag = ;
}
}
}
if(flag) {
puts("No");
return ;
} else {
puts("Yes");
for(int i = ; i<=n; i++) {
cout<<char('a'+c[i]-);
}
cout<<endl;
}
return ;
}
codeforces 623A. Graph and String 构造的更多相关文章
- [Codeforces 623A] Graph and String
[题目链接] http://codeforces.com/contest/623/problem/A [算法] 首先 , 所有与其他节点都有连边的节点需标号为'b' 然后 , 我们任选一个节点 , 将 ...
- codeforces 624C 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) 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 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- 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 Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题
E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...
- CodeForces 990D Graph And Its Complement(图和补图、构造)
http://codeforces.com/problemset/problem/990/D 题意: 构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b. 题解: 第一眼看到 ...
- Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)
题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...
随机推荐
- [转贴]JavaScript中Array(数组)的属性和方法
数组有四种定义的方式 使用构造函数:var a = new Array();var b = new Array(8); var c = new Array("first", &qu ...
- Android项目中包名的改动
通常改动包名时会造成R文件错误,而且有时带有原因不明的Manifest文件里多处文本混乱. 所以,将眼下觉得最为简洁方便的改动包名流程记录例如以下: 如果我们眼下的包名为com.pepper.util ...
- [Ext JS 4] 布局之实战一 - 中间区块不会自动伸展 (tab)
前言 [Ext JS 4] 布局之实战一 - 中间区块不会自动伸展 (tab) 在上一篇中,中间的tab 区块无法自动伸展的原因一句话说就是: 使用contentEL的方式,相关HTML元素不会参与组 ...
- codeforces #260 DIV 2 C题Boredom(DP)
题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...
- c语言中重要函数
gets函数,从标准输入读取一行文本,一行输入由一串字符组成,以一个换行符结尾: gets函数丢弃换行符,并在该行的末尾存储一个NUL字符(类似‘\0’), 然后返回一个非NULL值. 当gets函数 ...
- Css Rest 方法
在当今网页设计/开发实践中,使用CSS来为语义化的(X)HTML标记添加样式风格是 重要的关键.在设计师们的梦想中都存在着这样的一个完美世界:所有的浏览器都能够理解和适用多有CSS规则,并且呈现相同的 ...
- 关于js封装框架类库之事件模块
在触发DOM上的某个事件时,会产生一个事件对象event.这个对象中包含着所有与事件有关的信息.包括导致事件的元素,事件的类型以及其他与特定事件相关的信息. 例如: 鼠标操作点击事件时,事件对象中会获 ...
- eclipse修改编译路径
右击项目--properties--java build path--点击source,修改最下方的路径即可
- BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富( dp )
dp , dp[ i ][ j ] = max( dp[ k ][ j - 1 ] ) + G[ i ][ j ] ( i - 1 <= k <= i + 1 , dp[ k ][ j - ...
- C++对象模型6--对象模型对数据访问的影响
如何访问成员? 前面介绍了C++对象模型,下面介绍C++对象模型的对访问成员的影响.其实清楚了C++对象模型,就清楚了成员访问机制.下面分别针对数据成员和函数成员是如何访问到的,给出一个大致介绍. 对 ...