题目链接

给出一个图, 每个节点只有三种情况, 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 构造的更多相关文章

  1. [Codeforces 623A] Graph and String

    [题目链接] http://codeforces.com/contest/623/problem/A [算法] 首先 , 所有与其他节点都有连边的节点需标号为'b' 然后 , 我们任选一个节点 , 将 ...

  2. codeforces 624C Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 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 ...

  4. 图论:(Code Forces) Graph and String

    Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. 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 ...

  7. 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 ...

  8. CodeForces 990D Graph And Its Complement(图和补图、构造)

    http://codeforces.com/problemset/problem/990/D 题意: 构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b. 题解: 第一眼看到 ...

  9. Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)

    题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...

随机推荐

  1. GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上。基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要。利用这些项目,有时能够让你达到事半功倍的效果。

    1. ActionBarSherlock(推荐) ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便 ...

  2. XHProf 初探

    XHProf是一个分层PHP性能分析工具.它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况.一个函数的开销,可细分成调用者和被调用者的开销,XHProf数据收集阶段,它记录调 ...

  3. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  4. 【转】《分享一下我研究SQLSERVER以来收集的笔记》未整理

    分享一下我研究SQLSERVER以来收集的笔记 http://www.cnblogs.com/lyhabc/archive/2013/07/27/3219117.html

  5. NYOJ 14 会场安排问题(也算是经典问题了)

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就 ...

  6. move.js

    function startMove(obj,json,fn){ var flag=true;//标志所有运动是否到达目标值 clearInterval(obj.timer); obj.timer=s ...

  7. 本地yum源安装GCC

    Linux环境下yum源安装GCC 前提条件是有Linux环境的安装盘ISO文件 在Linux系统中创建两个目录,一个是用来存放ISO文件,一个是用来挂载该ISO文件,如下: $mkdir /root ...

  8. zoj 2256 Mincost

    #include<stdio.h> int main(void) { int kil; ; double sum; ) { sum=; flag=; while(kil) { ) { su ...

  9. 2015 5.16 C# 继承和多态

    类的层次结构有两种基本的构造方式  自顶向下  自底向上 基类的保护成员是指允许派生类的方法代码访问,而不是指通过派生类的对象访问 如果基类中的字段通过公有且可读写的属性进行了封装,那么建议将字段定义 ...

  10. Android应用开发基础篇(12)-----Socket通信

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/03/2378669.html 一.概述 网络通信无论在手机还是其他设备上都应用得非常广泛,因此掌 ...