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 现在,请构造一个这样的无向图, ...
随机推荐
- 动态更换view类的背景----StateListDrawable的应用
StateListDrawable可以根据View的不同状态,更换不同的背景 可以应用如EditText,Button等中,以Button为例 系统中默认的按钮被按下的颜色和未点击时的颜色不一样,该种 ...
- VB.NET版机房收费系统---SqlHelper
SqlHelper,最早接触这个词儿的时候,好像是13年的暑假,那个夏天来的比往年来的稍晚一些,呵呵,sqlhelper,翻译成中文就是数据库助手,帮手.百度百科这样对她进行阐述: SqlHelper ...
- POJ 2823 Sliding Window 【单调队列】
题目链接:http://poj.org/problem?id=2823 题目大意:给出一组数,一个固定大小的窗体在这个数组上滑动,要求出每次滑动该窗体内的最大值和最小值. 这就是典型的单调队列,单调队 ...
- 在基类中的析构函数声明为virtual
#include <iostream> using namespace std; class Father { public: ~Father() { cout << &quo ...
- 读书笔记 SQL 事务理解
事务的ACID属性 Atomicity 原子性 每个事务作为原子单元工作(即不可以再拆分),也就是说所有数据库变动事务,要么成功要么不成功. SQL Server把每个DML或者 DDL命令都当做一个 ...
- ztree树形插件
在开发项目中需要用到树插件,近期研究了几款树插件,好记性不如烂笔头 ,写下来 以后好查 MzTreeView(梅花雪) 很经典的树形菜单脚本控件 菜单树展示加载速度快 支持1w条以上大数据 缺点-- ...
- Auto-Layout 的各种坑Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
我们的很多人现在都在使用autolayout,用着也是非常爽但是有了这个东西以后更爽 很省事,什么都不用自己搞.Xcode完全搞定了,但是我终于为自己的懒惰付出了代价,再iphone4怎么运行怎么cr ...
- Objective-c 内存管理
与 C 有一点类似,oc 需要使用 alloc 方法申请内存.不同的是,c 直接调用 free 函数来释放内存,而 oc 并不直接调用 dealloc 来释放.整个 oc 都使用对象引用,而且每一 ...
- jQuery异步请求(如getJSON)跨域解决方案
相信大家在使用jQuery异步请求非自己网站内相对资源(通过别人站点上的URL直接读取)使经常会遇到如下错误吧,实际上这些错误都是浏览器安全机制“搞的鬼”,才让我们开发路上遇到了拦路虎. 当你直接在浏 ...
- 10.PHP 教程_PHP If...Else 语句
条件语句用于根据不同条件执行不同动作. PHP 条件语句 当您编写代码时,您常常需要为不同的判断执行不同的动作.您可以在代码中使用条件语句来完成此任务. 在 PHP 中,提供了下列条件语句: if 语 ...