要点

  • 将边作为染色,如果交叉则异色
#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(二分染色)的更多相关文章

  1. uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)

    Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...

  2. (简单) POJ 2492 A Bug's Life,二分染色。

    Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...

  3. Codeforces 1144F(二分染色)

    发现奇环不可行,偶环可行,考虑二分图.然后染色,方向全都从一种指向另一种就可以了,随意. ; int n, m, color[maxn]; vector<int> vc[maxn]; ve ...

  4. Codeforces 142B(二分染色、搜索)

    要点 会发现本质上棋盘分成了若干个独立集,本集合内的点放不放棋子并不影响其他集合内的 集合的划分方式就是满棋盘跳马步直到全跳过了,然后每个集合就分成两队,我们选人多的那队放棋子,人少那队当禁区 con ...

  5. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

  6. 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 ...

  7. Codeforces 732D [二分 ][贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. ...

  8. codeforces 359D 二分答案+RMQ

    上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...

  9. CodeForces 27D - Ring Road 2 构图2-sat..并输出选择方案

        题意             n个数1~n按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外.     题解 ...

随机推荐

  1. 鸟哥的linux私房菜 - 第三章 主机规划与磁盘分区

    各硬件装置在linux中的文件名 在linux系统中,每个装置都被当成一个档案来对待. 常见的装置与其在linux中的档名: 磁盘分区 磁盘链接的方式与装置文件名的关系 个人计算机常见的磁盘接口有两种 ...

  2. POJ 2976 Dropping tests:01分数规划【二分】

    题目链接:http://poj.org/problem?id=2976 题意: 共有n场考试,每场考试你得的分数为a[i],总分为b[i]. 你可以任意去掉k场考试. 问你最大的 100.0 * ( ...

  3. Go丨语言学习笔记--switch

    Java语言与Go语言的switch对比 Go语言 switch str { case "yes" : do something ... case "no" d ...

  4. unreal network

    frame move buffer: save move position recive server sync:All moves earlier than the ClientAdjustPosi ...

  5. java面试题06

    题目: 数据库 1. 表名:g_cardapply 字段(字段名/类型/长度): g_applyno varchar 8://申请单号(关键字) g_applydate bigint 8://申请日期 ...

  6. 重学JAVA基础(四):线程的创建与执行

    1.继承Thread public class TestThread extends Thread{ public void run(){ System.out.println(Thread.curr ...

  7. JS---计算两个日期之间相差多少天

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. Java虚拟机学习 - 体系结构 内存模型(转载)

    一:Java技术体系模块图 二:JVM内存区域模型 1.方法区 也称"永久代” .“非堆”,  它用于存储虚拟机加载的类信息.常量.静态变量.是各个线程共享的内存区域.默认最小值为16MB, ...

  9. sparse matrix format

    see Spare Matrix wikipedia item, and scipy's documentation on different choices of sparse matrix typ ...

  10. poj3535 A+B (大数加法)

    A+B Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 811   Accepted: 371 Description The ...