直接令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的更多相关文章

  1. CF741C.Arpa’s overnight party and Mehrdad’s silent entering [构造 二分图染色]

    CF741C - Arpa's overnight party and Mehrdad's silent entering 题意: 有 n 对情侣坐成一个圈,有两种食物Kooft and Zahre- ...

  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. Go的Select

    Go 的通道有两种操作方式,一种是带 range 子句的 for 语句,另一种则是 select 语句,它是专门为了操作通道而存在的.这里主要介绍 select 的用法. 一.select的语法 se ...

  2. sarama的消费者组分析、使用

    以前老的sarama版本不支持消费者组的消费方式,所以大多数人都用sarama-cluster. 后来sarama支持了消费者组的消费方式,sarama-cluster也停止维护了,但网上关于sara ...

  3. 干货 | 数据为王,携程国际火车票的 ShardingSphere 之路

    以下文章来源于携程技术 ,作者瑞华 作者简介 瑞华,携程高级后端开发工程师,关注系统架构.分库分表.微服务.高可用等. 一.前言 随着国际火车票业务的高速发展,订单量快速增长,单数据库瓶颈层面的问题逐 ...

  4. JS 开发中数组常用的方法

    大家有没有想过,js数组为什么会有这么多的方法,没错,就是为了不同场景下处理数据的需要,就像设计模式一样,都是为了能更好的处理当前场景的需要. 首先怎么创建一个数组呢, // 两种方式 // 1,构造 ...

  5. Java初步学习——2021.09.23每日报告,第三周周四

    (1)今天做了什么: (2)明天准备做什么? (3)遇到的问题,如何解决? 学习数组,编写了一个随机选牌的代码.自己最开始一直想只设置一个字符串数组,利用随机数来输出,但那样对字符串赋值会比较麻烦.可 ...

  6. dubbo注册中心占位符无法解析问题

    dubbo注册中心占位符无法解析问题 1.背景 最近搞了2个老项目,想把他们融合到一起.这俩项目情况简介如下: 项目一:基于SpringMVC + dubbo,配置读取本地properties文件,少 ...

  7. NC105 二分查找法

    二分查找(一) 二分查找看似简单,但是有很多的细节要注意. 题目是牛客NC105,找到有序数组中第一个大于或者等于所查找的数字. 初步写了如下的代码: class Solution { public: ...

  8. python jinja2初见

    吸取了长城杯的教训,学习python-web迫在眉睫. 正常难度的python_template_injection,由于现在没学面向对象,理解原理比较困难,所以先使用简单版复现:并附上正常版的常用p ...

  9. [no code][scrum meeting] Alpha 15

    项目 内容 会议时间 2020-04-23 会议主题 OCR紧急会议 会议时长 45min 参会人员 PM + OCR组(赵涛,黎正宇) 项目 内容 会议时间 2020-04-24 会议主题 全体测试 ...

  10. seata整合多数据源

    seata整合多数据源 一.背景 二.整合步骤 1.seata server的搭建 2.引入数据源切换组件 3.引入seata组件 4.配置多数据源 5.关闭seata自己默认的数据源代理 6.配置s ...