[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,求每个子树中最长的边,满 ...
随机推荐
- equals之List
School类 package com.collection.equals; /* * 定义一个学校类 相当于一个学校模板 * 状态: 1.学校id 2.学校名称 * */ public class ...
- FastAPI 学习之路(十二)接口几个额外信息和额外数据类型
系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...
- 不会SQL也能做数据分析?浅谈语义解析领域的机会与挑战
笔者按: 在第5次AI TIME PhD Debate上,笔者邀请了部分国内外语义解析领域的杰出华人学者共话语义解析的过去,现状和未来.本博客为笔者根据视频讨论总结的干货整理.对原视频感兴趣的同学可以 ...
- c语言中一条竖线是什么符号?
"|"在C语言中表示按位或,是双目运算符.其功能是参与运算的两数各对应的二进位(也就是最后一位)相或.只要对应的二个二进位有一个为1时,结果位就为1.参与运算的两个数均以补码出现. ...
- Go语言核心36讲(Go语言进阶技术五)--学习笔记
11 | 通道的高级玩法 我们已经讨论过了通道的基本操作以及背后的规则.今天,我再来讲讲通道的高级玩法. 首先来说说单向通道.我们在说"通道"的时候指的都是双向通道,即:既可以发也 ...
- 力扣 - 剑指 Offer 45. 把数组排成最小的数
题目 剑指 Offer 45. 把数组排成最小的数 思路1 将整数数组转化成字符串数组 然后使用Arrays工具类的sort方法帮助我们排序 代码 class Solution { public St ...
- 【UE4 C++】UKismetSystemLibrary 源代码
// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" # ...
- 5.31日 Scrum Metting
日期:2021年5月31日 会议主要内容概述:讨论草稿箱前后端接口,讨论账单页面设计. 一.进度情况 组员 负责 两日内已完成的工作 后两日计划完成的工作 工作中遇到的困难 徐宇龙 后端 文件导入功能 ...
- [no code][scrum meeting] Alpha 5
项目 内容 会议时间 2020-04-10 会议主题 后端技术讨论 会议时长 30min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalog() ...
- Noip模拟81 2021.10.20
T1 语言 比较简单的题,然后就瞎写了,所以考场上就我一个写了线段树的,所以我的常数.... 所以就枚举动词的位置,找前面后面有没有出现$4$即可 1 #include<bits/stdc++. ...