题目链接

给出一个图, 每个节点只有三种情况, 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. JPEGOPTIM压缩优化

    有关JPEGOPTIM JPEGOPTIM是CDN供应商Akamai开发的一个图片人优化的开源小工具. 它有较好的图片压缩效果(压缩比.图片质量), 比PHP的GD库算法要好. 详细的介绍可以看这个文 ...

  2. linux下解压iso文件

    .iso文件的格式是iso9660,iso9660是cd上的一种文件系统, 也就是说是 是数据在cd上的组织形式: 它的一些限制是: 1.最多8级子目录(可以用RockRidge Extension增 ...

  3. 怎样从一个DLL中导出一个C++类

    原文作者:Alex Blekhman    翻译:朱金灿 原文来源: http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx 译 ...

  4. VS2010/MFC对话框:向导对话框的创建及显示

    向导对话框的创建及显示 本节将为大家演示如何创建向导对话框. 仍然以前面的“加法计算器”的例子为基础,在其中加入向导对话框,我们可以用它来说明加法计算器的使用方法,一步一步引导用户操作,这也是比较常见 ...

  5. AppStore被拒原因及总结

    4.5 - Apps using background location services must provide a reason that clarifies the purpose of th ...

  6. Android animation学习笔记之view/drawable animation

    前一章中总结了android animation中property animation的知识和用法,这一章总结View animation和Drawable animation的有关知识: View ...

  7. uva 10548 - Find the Right Changes(拓展欧几里得)

    题目链接:uva 10548 - Find the Right Changes 题目大意:给定A,B,C,求x,y,使得xA+yB=C,求有多少种解. 解题思路:拓展欧几里得,保证x,y均大于等于0, ...

  8. EF 如何code first

    首先配置连接数据.sql server <connectionStrings> <add name="Model1" connectionString=" ...

  9. c 统计字符串中字符出现的个数

    1.单纯用数组来解题 思路:从左往右循环,每次碰到一个字符就和左边的字符串比较,如果有相同的就右移,如果没有找到相同的就从这个位置向右统计个数并输出. #include<stdio.h> ...

  10. Node.js模块os

    OS 操作系统模块 os.hostname() 操作系统的主机名. os.type() 操作系统的名称 os.release() 操作系统的发行版本 os.uptime() 当前系统的时间 以秒为 o ...