[cf741C]Arpa’s overnight party and Mehrdad’s silent entering
直接令2i-1和2i的位置不相同,相当于有2n条边,对其进行二分图染色即可(这张图一定不存在奇环)。
假设给出的n条关系是A类边,2i-1和2i的边是B类边,可以发现一条路径一定是AB交替(因为A/B的终点一定不可能是A/B的起点),那么环就一定是有等量的A边和B边,即偶环。

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 200005
4 struct ji{
5 int nex,to;
6 }edge[N<<1];
7 int E,n,a[N],head[N],x[N],y[N];
8 void add(int x,int y){
9 edge[E].nex=head[x];
10 edge[E].to=y;
11 head[x]=E++;
12 }
13 void dfs(int k,int sh){
14 if (a[k]>=0)return;
15 a[k]=sh;
16 for(int i=head[k];i!=-1;i=edge[i].nex)dfs(edge[i].to,sh^1);
17 }
18 int main(){
19 scanf("%d",&n);
20 memset(head,-1,sizeof(head));
21 memset(a,-1,sizeof(a));
22 for(int i=1;i<=n;i++){
23 scanf("%d%d",&x[i],&y[i]);
24 add(x[i],y[i]);
25 add(y[i],x[i]);
26 add(2*i-1,2*i);
27 add(2*i,2*i-1);
28 }
29 for(int i=1;i<=2*n;i++)
30 if (a[i]==-1)dfs(i,0);
31 for(int i=1;i<=n;i++)printf("%d %d\n",a[x[i]]+1,a[y[i]]+1);
32 }
[cf741C]Arpa’s overnight party and Mehrdad’s silent entering的更多相关文章
- CF741C.Arpa’s overnight party and Mehrdad’s silent entering [构造 二分图染色]
CF741C - Arpa's overnight party and Mehrdad's silent entering 题意: 有 n 对情侣坐成一个圈,有两种食物Kooft and Zahre- ...
- 二分图匹配 + 构造 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,求每个子树中最长的边,满 ...
随机推荐
- 精准容量、秒级弹性,压测工具 + SAE 方案如何完美突破传统大促难关?
作者 | 代序 阿里云云原生技术团队 本文整理自<Serverless 技术公开课>,"Serverless"公众号后台回复"入门",即可获取系列文 ...
- FastAPI 学习之路(十四)响应模型
系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...
- TypeError: module() takes at most 2 arguments (3 given)
1. 错误提示 2. 代码 class Parent: """定义父类""" def __init__(self): print(" ...
- Win10 配置JDK1.8 (JDK 8)环境变量
JDK的安装: 1. JDK安装过程中,一般X掉公共JRE,因为JDK包含了JRE: 环境变量的配置: 1. 打开环境变量,编辑系统变量,新建: 变量名:JAVA_HOME 变量值:D:\so ...
- 【二食堂】Beta - Scrum Meeting 12
Scrum Meeting 12 例会时间:5.27 20:00~20:10 进度情况 组员 当前进度 今日任务 李健 1. 知识图谱导出功能完成 issue 1. 继续完成文本保存的工作 issue ...
- PCB板HDI板几阶是什么意思
http://blog.sina.com.cn/s/blog_55ff6d5d0102xxvx.html
- 广域网(ppp协议、HDLC协议)
文章转自:https://blog.csdn.net/weixin_43914604/article/details/105028759 学习课程:<2019王道考研计算机网络> 学习目的 ...
- OpenWrt编译问题记录
错误一.config.status: error: cannot find input file: `xmetadataretriever/Makefile.in' configure: creati ...
- Luogu P1118 [USACO06FEB]数字三角形 Backward Digit Sums | 搜索、数学
题目链接 思路:设一开始的n个数为a1.a2.a3...an,一步一步合并就可以用a1..an表示出最后剩下来的数,不难发现其中a1..an的系数恰好就是第n层杨辉三角中的数.所以我们可以先处理出第n ...
- no active checks on server [192.168.1.101:10051]: host [ ] not found
1.查看/etc/zabbix/zabbix_agentd.conf的 hostanme 2.查看zabbix-web中,主机名称 3.将zabbix-web的主机名改成/etc/zabbix/zab ...