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 现在,请构造一个这样的无向图, ...
随机推荐
- perl lwp get uft-8和gbk
gbk编码: jrhmpt01:/root/lwp# cat x2.pl use LWP::UserAgent; use DBI; $user="root"; $passwd='R ...
- 宣布发布全新的 Windows Azure 缓存预览版
全新 Windows Azure 缓存的预览版现已发布.此托管服务可以提供闪电般的数据访问速度,以帮助您构建更具可伸缩性.响应更快的应用程序. 详情如下: · 托管式缓存:这一全新的托管服务为需 ...
- HTML语法
2014-01-21/21:28:59 网页制作概述 HTML是WEB页面的描述性语言 CSS为HTML样式机制 JavaScript为交互WEB设计最佳选择 CSS\JavaScript\PHP都可 ...
- Java学习——Ubuntu下jdk的安装以及Java环境的配置
第一步.下载 到官网下载jdk,在Java SE Development Kit 7uXX里面,把Accept License Agreement 打勾,这样才能下载jdk,然后我们选择对应的Ubun ...
- 去掉android的屏幕上的title bar
在配置文件里修改 (关键代码:android:theme="@android:style/Theme.NoTitleBar.Fullscreen",如果想只是去除标题栏就后面不用加 ...
- php 计算多维数组中所有值的总和
php 内置函数 array_sum() 函数返回数组中所有值的总和,只能返回一维数组的总和: 计算多维数组所有值的和就要自定义函数了: function get_sum($array) { $num ...
- A Byte of Python 笔记(5)函数:定义、形参、局部变量、默认参数、关键参数
第7章 函数 函数是重要的程序段.它们允许你给一块语句一个名称,然后你可以在程序的任何地方使用这个名称任意多次地运行这个语句块.这被称为 调用 函数. 定义函数 函数通过 def 关键字定义.def ...
- [转]Swift 编程语言入门教程
今天在网上看到一篇非常好的教程,分享给大家 原文地址:http://gashero.iteye.com/blog/2075324 目录 1 简介 2 Swift入门 3 简单值 4 控 ...
- 分组求和SQL示例
1.ROLLUP和CUBE函数,自动汇总数据 select * from test_tbl的数据这样的 col_a col_b col_c ---- ----- ...
- PCB的整个加工流程
1 MI:制作生产流程卡,指导产线如何去生产出所需要的pcb.2 内层:PCB,除了最便宜的单层板,简单的双层板,有时候需要使用4层 6层 8层,以实现复杂的连 接关系和高密度,再就是减少干扰或者降低 ...