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按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外. 题解 ...
随机推荐
- PHP的深copy和浅copy
1.对象复制的由来 为什么对象会有“复制”这个概念,这与PHP5中对象的传值方式是密切相关的,让我们看看下面这段简单的代码 /** * 电视机类 */ class Television { /** * ...
- Jmeter-线程日志查看
jstack可以定位到线程堆栈,根据堆栈信息我们可以定位到具体代码,所以它在JVM性能调优中使用得非常多. 1. 压测时,使用top命令查看哪个java进行占用了较多的CPU资源: 上图中可以看出p ...
- Multiple webcams on ZoneMinder
Monitoring a 3D Printer I have tidied my new workshop and I am starting to play with 3d-printing aga ...
- BZOJ1568:[JSOI2008]Blue Mary开公司
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- WPF 使用MultiBinding ,TwoWay ,ValidationRule ,需要注意的事项
当wpf使用multibinding时, 其内部的validaterule的value 是其多个Binding的值, 要根据情况去验证, 还有就是在做IMultiConverter的ConvertBa ...
- 面向对象(this关键字)
package com_package2; public class Person3 { private int age; private String name; public int getAge ...
- eclipse必备快捷键
1.[ Ctrl + Shift+ P ],查找括号的开始和闭合 2.[ALT+/],这个快捷键应该没有人不知道 3.[Ctrl+O],显示类中方法和属性的大纲,能快速定位类的方法和属性,在查找Bu ...
- 《精通Spring4.X企业应用开发实战》读后感第五章(注入参数详解)
- 面试总结hashmap
考点: 1.hashing的概念 2.HashMap中解决碰撞的方法 3.equals()和hashCode()的应用,以及它们在HashMap中的重要性 4.不可变对象的好处 5.HashMap多线 ...
- 快速部署Kubernetes集群管理
这篇文章介绍了如何快速部署一套Kubernetes集群,下面就快速开始吧! 准备工作 //关闭防火墙 systemctl stop firewalld.service systemctl disabl ...