CF741C.Arpa’s overnight party and Mehrdad’s silent entering [构造 二分图染色]
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 [构造 二分图染色]的更多相关文章
- [cf741C]Arpa’s overnight party and Mehrdad’s silent entering
直接令2i-1和2i的位置不相同,相当于有2n条边,对其进行二分图染色即可(这张图一定不存在奇环). 假设给出的n条关系是A类边,2i-1和2i的边是B类边,可以发现一条路径一定是AB交替(因为A/B ...
- 二分图匹配 + 构造 E. Arpa’s overnight party and Mehrdad’s silent entering
http://codeforces.com/contest/742/problem/E 跪着看题解后才会的. 对于任何一对BF[i]和GF[i] 连接了一条边后,那么他们和隔壁都是不会有边相连的了,这 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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,求每个子树中最长的边,满 ...
随机推荐
- IScroll5不能滑到最底端的解决办法
IScroll总体上用起来比较简单,但是如果用不好的可能会产生底部一点滚动不上去的问题. 环境:weui+iscroll5 整体布局及id如下 searchbarwrapper divscroll ...
- CSS之Background
实验环境 [Windows 10] Chrome 73.0.3683.103(386,64bit) background作用范围 content+padding 参考文献 [1] CSS backgr ...
- redis集群配置与管理
Redis在3.0版本以后开始支持集群,经过中间几个版本的不断更新优化,最新的版本集群功能已经非常完善.本文简单介绍一下Redis集群搭建的过程和配置方法,redis版本是5.0.4,操作系统是中标麒 ...
- Python核心编程(网络编程)
1.python socket模块内置方法 2.tcp服务器伪代码 3.tcp客户端伪代码 4.socket模块属性 5.一个简单的tcp客户端和服务端 服务端代码: # encoding:utf-8 ...
- TensorFlow在Windows上的CPU版本和GPU版本的安装指南(亲测有效)
安装说明 平台:Window.Ubuntu.Mac等操作系统 版本:支持GPU版本和CPU版本 安装方式:pip方式.Anaconda方式 attention: 在Windows上目前支持python ...
- cout,cerr和clog的区别
官方解释: cout——Standard output stream Object of class ostream that represents the standard output strea ...
- error while loading shared libraries: libopencv_core.so.3.4: cannot open shared object file: No such file or directory
1. 将CMakeLists.txt 文件中 find_package(OpenCV REQURED)补充完整为带版本号的:find_package(OpenCV 2.4.9 REQURED) 2. ...
- Python爬虫案例-获取最新的中国行政区域划分
源网页:中国统计局标准 http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/ 打开网页后可以分析出行政区域划分共分为5层 根据传入参数,生成网页 ...
- javascript闭包学习
(function(){})()===>>>>函数会被立即执行function(){}是一个函数用括号包起来表示是函数表达式再加()表示函数自执行 如何理解闭包?1.定义和用 ...
- MinGW GCC 8.3.1 2019年2月23日 出炉啦
GNU 2019-02-22 发布了 GCC 8.3 https://gcc.gnu.org/onlinedocs/8.3.0/ 有详细的说明 MinGW 上可用的 GCC 8.3.1 版本下载地址 ...