cf623A. Graph and String(二分图 构造)
题意

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(二分图 构造)的更多相关文章
- 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 ...
- 浮点数运算结果不精确,以及用String来构造BigDecimal进行浮点数精确计算
1.浮点数运算结果不精确 先看如下代码 System.out.println(1.0 - 0.8); System.out.println(0.2 + 0.1); System.out.println ...
- 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 ...
- 【题解】CF742E (二分图+构造)
[题解]CF742E (二分图+构造) 自闭了CodeForces - 742E 给定的条件就是一个二分图的模型,但是有一些不同.不同就不同在可以出现相邻两个点颜色相同的情况. 构造常用方法之一是按奇 ...
- codeforces 624C Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 623A. Graph and String 构造
题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...
- [leetcode] 根据String数组构造TreeNode,用于LeetCode树结构相关的测试用例
LeetCode 跟树结构相关的题目的测试用例中大多是通过String数组来构造树.例如{2,#,3,#,4,#,5,#,6},可以构造出如下的树(将树结构逆时针选择90度显示): 6 ...
- [LeetCode] Is Graph Bipartite? 是二分图么?
Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipart ...
随机推荐
- css实现带箭头的流程条
直接上效果图: <ul class="navs"> <li>1</li> <li>2</li> <li>3& ...
- 【bzoj3489】 A simple rmq problem k-d树
由于某些原因,我先打了一个错误的树套树,后来打起了$k-d$.接着因不明原因在思路上被卡了很久,在今天中午蹲坑时恍然大悟...... 对于一个数字$a_i$,我们可以用一组三维坐标$(i,pre,nx ...
- js03
我们接着来学习js的一些基础知识点. 1.document: document是window对象的一个属性.window对象表示浏览器中打开的窗口.如果文档包含框架(frame或者iframe),浏览 ...
- 3、Xamarin Forms 调整安卓TabbedPage 下置
降低学习成本是每个.NET传教士义务与责任. 建立生态,保护生态,见者有份. 教程晦涩难懂是我的错误. 对于默认的TabbedPage 上面进行页面切换 上面是安卓默认的情况 对我们大部分人来说都 ...
- 剑指offer五十五之链表中环的入口结点
一.题目 一个链表中包含环,请找出该链表的环的入口结点. 二.思路 方法一: 假设x为环前面的路程(黑色路程),a为环入口到相遇点的路程(蓝色路程,假设顺时针走), c为环的长度(蓝色+橙色路程). ...
- (转)python函数: 内置函数
原文:https://blog.csdn.net/pipisorry/article/details/44755423 https://juejin.im/post/5ae3ee096fb9a07aa ...
- Java之集合(十七)ConcurrentLinkedQueue
转载请注明源出处:http://www.cnblogs.com/lighten/p/7491057.html 1.前言 ConcurrentLinkedQueue是一个无界的线程安全队列,遵循FIFO ...
- 各种”xxx“ native gem required installed build tools 报错
报错情况:(类似毛病 提示native gem require installed builld tools的解决方法是一样的)) 解决方法:http://rubyinstaller.org/down ...
- mysql 一个表内根据字段对应值不同查询统计总数
- 如何删除Eclipse里某个工作空间?
很多时候,一个Eclipse中或多或少的都会有那么几个工作空间(workspace),但是久而久之你会发现有些工作空间你觉得不再需要了或者觉得碍眼,怎么办? 其实很简单,方法有两种. 1.打开你的Ec ...