CF741C - Arpa’s overnight party and Mehrdad’s silent entering

题意:

有 n 对情侣坐成一个圈,有两种食物Kooft and Zahre-mar,要给每个人分其中一种,要求每对情侣的食物不同,任意连续的三个人必须要有两人食物不同。

求分配方案,无解输出-1

1≤n ≤100000


注意:“Kooft” is something make people die. “Zahre-mar” meaning is “Venom of Snake”.

好开心啊

构造。

情侣连边。为满足连续三人有两人不同,强制2i和2i+1连边。

这样不会产生奇环,一定有解,二分图染色

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 2e5+5; int n, a[N], b[N];
struct edge {
int v, ne;
} e[N<<1];
int cnt, h[N];
inline void ins(int u, int v) {
e[++cnt] = (edge) {v, h[u]}; h[u] = cnt;
e[++cnt] = (edge) {u, h[v]}; h[v] = cnt;
} int col[N];
void dfs(int u, int p) {
col[u] = p;
for(int i=h[u]; i; i=e[i].ne) {
int v = e[i].v;
if(col[v]) continue;
dfs(v, 3-p);
}
}
int main() {
//freopen("in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(); cout.tie();
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i] >> b[i];
ins(a[i], b[i]);
ins(i<<1, i<<1|1);
} for(int i=1; i<=n<<1; i++) if(!col[i]) dfs(i, 1);
for(int i=1; i<=n; i++) cout << col[a[i]] << ' ' << col[b[i]] << '\n';
}

CF741C.Arpa’s overnight party and Mehrdad’s silent entering [构造 二分图染色]的更多相关文章

  1. [cf741C]Arpa’s overnight party and Mehrdad’s silent entering

    直接令2i-1和2i的位置不相同,相当于有2n条边,对其进行二分图染色即可(这张图一定不存在奇环). 假设给出的n条关系是A类边,2i-1和2i的边是B类边,可以发现一条路径一定是AB交替(因为A/B ...

  2. 二分图匹配 + 构造 E. Arpa’s overnight party and Mehrdad’s silent entering

    http://codeforces.com/contest/742/problem/E 跪着看题解后才会的. 对于任何一对BF[i]和GF[i] 连接了一条边后,那么他们和隔壁都是不会有边相连的了,这 ...

  3. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  4. Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...

  5. Arpa's weak amphitheater and Mehrdad's valuable Hoses

    Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per ...

  6. Arpa's loud Owf and Mehrdad's evil plan

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  7. Codeforces Round #383 (Div. 2)C. Arpa's loud Owf and Mehrdad's evil plan

    C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 me ...

  8. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution

    B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...

  9. CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]

    D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...

随机推荐

  1. JGUI源码:JS菜单动态绑定(8)

    我们知道Jquery绑定事件后的新添加的对象是不响应事件的,为了解决这个问题,动态添加的对象需要从新绑定,使用一个init方法实现代码如下 //Accordion封装 (function($) { J ...

  2. 一次基于innobackupex备份及binlog的单表恢复操作

    [环境介绍] 系统环境:Red Hat Enterprise Linux Server release 7.0 (Maipo) + Server version: 5.7.18-log MySQL C ...

  3. CORS跨域 Ajax headers 问题

    今天我们遇到了一个CORS跨域的问题Ajax如下 var url = "http://localhost:11980/api/Demo/GetString"; //api地址 $. ...

  4. “不能在dropdownlist中选择多个项

    DropDownList.ClearSelection(); DropDownList.SelectedItem.Text = "value值";

  5. vue项目打包笔记

    我的需求是在同一个代码目录下,可以同时放入两个项目包,通过运行不同的命令,运行相应的项目页面以及打包相应的项目. 这样的话,代码管理比较方便,用于多个项目在同一时间开发,类型一样,但在功能上有所区分的 ...

  6. Triplet Loss(转)

    参考:https://blog.csdn.net/u013082989/article/details/83537370 作用:用于对差异较小的类别进行区分

  7. Appnium-API-Status

    Status Java:// TODO Python:selenium.webdriver.common.utils.is_url_connectable(port) Description Retu ...

  8. 【原创】Linux基础之vi

    vi配置文件 ~/.vimrcor/etc/vimrc 模式 命令模式(Command Mode) 1 上/下/左/右移动光标 i/k/j/l 2 跳到文件末尾 G 3 跳到文件开头 gg 4 向下搜 ...

  9. java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.

    java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.M ...

  10. cocos2dx-lua http请求下载图片,使用XMLHttpRequest类

    HttpFileDownLoadSimple.lua local downloader = {} --数据拆分,以没1024*5字节拆成一段,打包写入文件 (拆完再拼接,转成字符串) local fu ...