题意

题目链接

Sol

可以这样考虑,在原图中没有边相连的点的值肯定是a / c

那么直接二分图染色即可

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 1001, INF = 1e9 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, mp[MAXN][MAXN], col[MAXN], inder[MAXN];
bool flag = 1;
void dfs(int x) {
for(int i = 1; i <= N; i++)
if(!mp[x][i])
if(col[i] == -1) col[i] = col[x] ^ 1, dfs(i);
}
int main() {
N = read(); M = read();
for(int i = 1; i <= N; i++) mp[i][i] = 1;
for(int i = 1; i <= M; i++) {
int x = read(), y = read();
mp[x][y] = mp[y][x] = 1;
}
for(int i = 1; i <= N; i++)
for(int j = i + 1; j <= N; j++)
if(!mp[i][j]) inder[i]++, inder[j]++;
memset(col, -1, sizeof(col));
for(int i = 1; i <= N; i++) if(col[i] == -1) col[i] = 0, dfs(i);
for(int i = 1; i <= N; i++) {
for(int j = i + 1; j <= N; j++) {
if(!mp[i][j] && (col[i] == col[j])) {puts("NO"); return 0;}
if(mp[i][j] && inder[i] && inder[j] && (col[i] != col[j])) {puts("NO"); return 0;}
}
}
puts("Yes");
for(int i = 1; i <= N; i++)
if(inder[i] == 0) putchar('b');
else if(col[i] == 1) putchar('c');
else putchar('a');
return 0;
}

cf623A. Graph and String(二分图 构造)的更多相关文章

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

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

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

  3. 浮点数运算结果不精确,以及用String来构造BigDecimal进行浮点数精确计算

    1.浮点数运算结果不精确 先看如下代码 System.out.println(1.0 - 0.8); System.out.println(0.2 + 0.1); System.out.println ...

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

  5. 【题解】CF742E (二分图+构造)

    [题解]CF742E (二分图+构造) 自闭了CodeForces - 742E 给定的条件就是一个二分图的模型,但是有一些不同.不同就不同在可以出现相邻两个点颜色相同的情况. 构造常用方法之一是按奇 ...

  6. codeforces 624C Graph and String

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

  7. codeforces 623A. Graph and String 构造

    题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...

  8. [leetcode] 根据String数组构造TreeNode,用于LeetCode树结构相关的测试用例

    LeetCode 跟树结构相关的题目的测试用例中大多是通过String数组来构造树.例如{2,#,3,#,4,#,5,#,6},可以构造出如下的树(将树结构逆时针选择90度显示): 6         ...

  9. [LeetCode] Is Graph Bipartite? 是二分图么?

    Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipart ...

随机推荐

  1. springboot入门之简单demo

    项目构建 我们采用maven构建SpringBoot工程,首先创建一个maven工程,对应的pom文件如下: <properties> <java.version>1.8< ...

  2. 缓存行和cpu缓存实例

    并发框架Disruptor译文 剖析Disruptor:为什么会这么快?(一)锁的缺点 剖析Disruptor:为什么会这么快?(二)神奇的缓存行填充 剖析Disruptor:为什么会这么快?(三)伪 ...

  3. 把本地git仓库的项目上传到远程仓库

    之前在学校实验室服务器上建了一个git远程仓库,存放我写的express项目代码.后来由于出去实习,就无法访问那个远程仓库了,因为它在校园网内. 还好我的笔记本中有这个项目完整的本地仓库,于是我就试着 ...

  4. nacicat premium 快捷键

    1.ctrl+q          打开查询窗口 2.ctrl+/           注释sql语句 3.ctrl+shift +/  解除注释 4.ctrl+r          运行查询窗口的s ...

  5. TestNG的常用注解

    @BeforeSuite:表示此注解的方法会在当前测试集合(Suite)中的任一测试用例开始运行之前执行 @AfterSuite:表示此注解的方法会在当前测试集合(Suite)中的所有测试程序运行结束 ...

  6. MySQL索引(六)

    一.什么是索引 索引就像一本书的目录一样,如果在字段上建立索引,那么以索引为列的查询条件时可以加快查询的速度,这个就是MySQL优化的重要部分 二.创建主键索引 整个表的每一条记录的主键值在表内都是唯 ...

  7. ubuntu 镜像站部署

    定时任务 #mirror web */5 * * * * cd /mirror && git pull #mysql mirror 0 */3 * * * rsync -av --de ...

  8. 数据库MySQL(课下作业,必做)

    数据库MySQL(课下作业,必做) 题目要求: 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入 ...

  9. C# 对象相等性判断和同一性判断

    在日常开发中经常需要编写代码比较不同的对象.例如,有时需要将对象都放到一个集合中,并编写代码对集合中的对象进行排序.搜索或者比较. System.Object类有两个Equals方法,如下: 1.实例 ...

  10. Spring中的BeanPostProcessor

    一.何谓BeanProcessor BeanPostProcessor是SpringFramework里非常重要的核心接口之一,我先贴出一段源代码: /* * Copyright 2002-2015 ...