Codeforces 1144F(二分染色)
发现奇环不可行,偶环可行,考虑二分图。然后染色,方向全都从一种指向另一种就可以了,随意。
const int maxn = 2e5 + ;
int n, m, color[maxn];
vector<int> vc[maxn];
vector<P> e; void dfs(int cur, int co) {
color[cur] = co;
for (auto i : vc[cur]) {
if (!color[i]) {
dfs(i, - co);
} else if (color[i] == color[cur]) {
puts("NO");
exit();
}
}
} int main() {
read(n), read(m);
rep(i, , m) {
int u, v;
read(u), read(v);
vc[u].push_back(v);
vc[v].push_back(u);
e.push_back({u, v});
} dfs(, );
puts("YES");
for (auto i : e) {
write(color[i.first] < color[i.second]);
}
return ;
}
Codeforces 1144F(二分染色)的更多相关文章
- uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)
Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...
- (简单) POJ 2492 A Bug's Life,二分染色。
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...
- Codeforces 1144F Graph Without Long Directed Paths (DFS染色+构造)
<题目链接> 题目大意:给定一个无向图,该无向图不含自环,且无重边.现在要你将这个无向图定向,使得不存在任何一条路径长度大于等于2.然后根输入边的顺序,输出构造的有向图.如果构造的边与输入 ...
- Codeforces 27D(二分染色)
要点 将边作为染色,如果交叉则异色 #include <cstdio> #include <algorithm> #include <functional> usi ...
- Codeforces 1144F Graph Without Long Directed Paths DFS染色
题意: 输入一张有向图,无自回路和重边,判断能否将它变为有向图,使得图中任意一条路径长度都小于2. 如果可以,按照输入的边的顺序输出构造的每条边的方向,构造的边与输入的方向一致就输出1,否则输出0. ...
- Graph Without Long Directed Paths CodeForces - 1144F (dfs染色)
You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self ...
- Codeforces 142B(二分染色、搜索)
要点 会发现本质上棋盘分成了若干个独立集,本集合内的点放不放棋子并不影响其他集合内的 集合的划分方式就是满棋盘跳马步直到全跳过了,然后每个集合就分成两队,我们选人多的那队放棋子,人少那队当禁区 con ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
随机推荐
- DB主从一致性的几种解决方法
https://www.cnblogs.com/KunLunSu/p/6826247.html
- (org.openqa.selenium.WebDriverException: Unable to launch the app: Error: Trying to start logcat capture but it's already started! )错误解决办法
新增: capabilities.setCapability("autoLaunch",false); 将setup中的: driver = new AndroidDriver(n ...
- 基于DM642 RAW采集格式的视频驱动开发及应用
摘 要:为解决C64X系列数字信号处理器(DSP)视频驱动不能应用于原始数据格式(RAW)采集格式的问题,设计了DM642和电耦合元件(CCD)高清传感器的数据传输接口,并分析.修改用于标准格式的视频 ...
- HDOJ_ How can I read input data until the end of file ?
Language C C++ Pascal To read numbers int n;while(scanf("%d", &n) != EOF){ ...} int n; ...
- forEach、for-in与for-of的区别
forEach.for-in与for-of的区别 forEach介绍 objArr.forEach(function (value) { console.log(value); }); foreach ...
- 初识Restful(学习笔记)
什么是Restful? REST -- Resource Representational State Transfer(表现层状态转移) 本质上是一种优雅的URL表达方式,描述资源的状态和状态的转移 ...
- HDU2255 奔小康赚大钱 【模板】 二分图完美匹配
基本概念 二分图有两个种点:X和Y.X与Y之间存在一些边,每个边有一个权值.现要求求一组X与Y间的通过边实现的一一匹配,使得得到的边权和最大. 总体过程 对每个X节点设置一个顶标Xl,初值为与X相邻的 ...
- fork函数的使用【学习笔记】
#include "apue.h" ; char buf[] = "a write to stdout\r\n"; int main(void) { int v ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- mpvue——实现点击数组内的某一元素进行置顶(排序第一)操作
前言 其实很简单只是用了js的几个函数 substr unshift splice 完整代码 | mpvue模仿QQ 代码 思路很简单,获取当前元素下标然后通过unshift函数将该值插入到数组第一位 ...