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按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外. 题解 ...
随机推荐
- Download rtsp.c
1. [代码][C/C++]代码 /* * Copyright (c) 2011, Jim Hollinger * All rights reserved. * * Redistribution an ...
- HTML5实现中国象棋游戏(无人能敌)
1. [代码][JavaScript]代码 var AI = AI||{}; AI.historyTable = {}; //历史表 //人工智能初始化AI.init = func ...
- Java微信公众平台开发_03_消息管理之被动回复消息
GitHub源码:https://github.com/shirayner/weixin_gz 一.本节要点 1.回调url 上一节,我们启用服务器配置的时候,填写了一个服务器地址(url),如下图, ...
- BZOJ3230 相似子串[后缀数组+二分+st表]
BZOJ3230 相似子串 给一个串,查询排名i和j的子串longest common suffix和longest common prefix 思路其实还是蛮好想的,就是码起来有点恶心.可以发现后缀 ...
- ACM学习历程——HDU4472 Count(数学递推) (12年长春区域赛)
Description Prof. Tigris is the head of an archaeological team who is currently in charge of an exca ...
- 媒体格式分析之flv -- 基于FFMPEG
本来是应该先写一个媒体文件格式的简单讲解的,还没来得及写,以后再写.今天就先根据ffmpeg的flv.c的flv_demux这个结构体来讲解一下当前比较流行的媒体格式flv. FLV 是FLASH V ...
- ScikitLearn 学习器类型
源自在线课程的学习:http://www.studyai.com/course/detail/d086826e9be84b818f9c54893633663d
- AtCoder Regular Contest 072 E:Alice in linear land
题目传送门:https://arc072.contest.atcoder.jp/tasks/arc072_c 题目翻译 给你一个数组\(D\),然后给你一个操作序列\(d\),每次操作可以将\(D\) ...
- JS---设置简易红绿灯
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- C#自定义控件 类似于Linechart
界面效果: 对外提供的属性设置 /// <summary> /// 背景色 /// </summary> public Color BackColor; /// <sum ...