Codeforces 27D(二分染色)
要点
- 将边作为染色,如果交叉则异色
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int n, m;
int a[101], b[101], c[101];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", &a[i], &b[i]);
if (a[i] > b[i])
swap(a[i], b[i]);
c[i] = -1;
}
function<void(int, int)> dfs = [&](int u, int color) {
if (c[u] != -1 && c[u] != color) {
puts("Impossible"); exit(0);
} else if (c[u] == -1) {
c[u] = color;
for (int i = 1; i <= m; i++) {
if (a[i] < a[u] && b[i] > a[u] && b[i] < b[u])
dfs(i, color ^ 1);
if (a[i] > a[u] && a[i] < b[u] && b[i] > b[u])
dfs(i, color ^ 1);
}
}
};
for (int i = 1; i <= m; i++)
if (c[i] < 0)
dfs(i, 0);
for (int i = 1; i <= m; i++)
putchar(c[i] ? 'i' : 'o');
}
Codeforces 27D(二分染色)的更多相关文章
- 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(二分染色)
发现奇环不可行,偶环可行,考虑二分图.然后染色,方向全都从一种指向另一种就可以了,随意. ; int n, m, color[maxn]; vector<int> vc[maxn]; ve ...
- 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 ...
- Codeforces 732D [二分 ][贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. ...
- codeforces 359D 二分答案+RMQ
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...
- CodeForces 27D - Ring Road 2 构图2-sat..并输出选择方案
题意 n个数1~n按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外. 题解 ...
随机推荐
- python基础-正则2
正则函数 Python提供re模块,包含所有正则表达式的功能 由于python的字符串本身也有\转义,所以需要注意: s = "ABC\\-001" 对应的正则表达式应为:'ABC ...
- 主库报 Error 12154 received logging on to the standby PING[ARC2]
主备网络配置存在问题 一系列报错 [root@node1 bin]# ./srvctl start database -d devdbPRCR-1079 : Failed to start reso ...
- CentOS7的网络配置
1.DNS配置 新安装的虚拟机,ping 内网IP可以,但是ping 外网域名却失败,告知“Name or service not known”. 原来是因为需要在/etc/sysconfig/net ...
- BZOJ2329:[HNOI2011]括号修复
浅谈\(splay\):https://www.cnblogs.com/AKMer/p/9979592.html 浅谈\(fhq\)_\(treap\):https://www.cnblogs.com ...
- python json ajax django四星聚会
什么是json: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...
- AR/VR-VR-Info-Micron-Insight:一镜观一屋:VR 将建筑设计变为现实
ylbtech-AR/VR-VR-Info-Micron-Insight:一镜观一屋:VR 将建筑设计变为现实 1.返回顶部 1. 一镜观一屋:VR 将建筑设计变为现实 想象一下,在一栋为你设计的还没 ...
- GBK点阵显示字库的制作和使用
转自:http://blog.csdn.net/exbob/article/details/6539643 GBK编码共收录汉字21003个.符号883个,并提供1894个造字码位,简.繁体字融于一库 ...
- Elasticsearch的前后台运行与停止(rpm包方式)
对应,这es的下载,需要rpm包. Elasticsearch-2.4.3的下载(图文详解) 建议用root用户 [root@djt002 elasticsearch-2.4.3]$ pwd/usr/ ...
- GridView中数据行的操作
一个是直接动态绑定gridview 用3楼的办法就可以了 int j=1;//j的数值表示你要取的那一列的索引,要取第二列,j就设为1for (int i = 0; i < this.GridV ...
- [hdu4738]求桥模板
oj问题,待修改,存档. #include<stdio.h> #include<iostream> #include<cstdio> #include<sta ...