URAL 1320 Graph Decomposition(并查集)
1320. Graph Decomposition
Memory limit: 64 MB
is a simple graph with an even number of edges. You are to define if it
is possible to present it by the set of pairs of adjacent edges (having
a common vertex).
Input
a sequence of the numbers pairs. Each pair denotes vertices identifiers
of one edge. All the identifiers are integers from 1 to 1000. You may
assume that there are no loops and multiple edges in the graph defined
by the input data.
Output
Samples
| input | output | 
|---|---|
1 2  | 
1  | 
1 2  | 
0  | 
Problem Author: Idea: Alexander Petrov, prepared by Alexander Petrov, Leonid Volkov
【分析】每次删除相邻的两条边,问是否能全部删除干净。偶数条边,每条边两个顶点,也就是说如果能删除干净,则每个连通块中所有点的度数之和能够整除4.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int edg[N][N],vis[N];
int in[N],parent[N],n;
int Find(int x)
{
if(parent[x]!=x)parent[x]=Find(parent[x]);
return parent[x];
}
void Union(int x,int y)
{
x=Find(x);y=Find(y);
if(x==y)return;
parent[y]=x;
}
int main()
{
int u,v,num=;
for(int i=;i<N;i++)parent[i]=i;n=;
while(~scanf("%d%d",&u,&v)){
Union(u,v);
in[u]++;in[v]++;
n=max(n,max(u,v));
}
bool ok=true;
for(int i=;i<=n;i++){
vis[Find(i)]+=in[i];
}
for(int i=;i<=n;i++){
if(vis[Find(i)]%!=)ok=false;
}
if(ok)puts("");
else puts("");
return ;
}
URAL 1320 Graph Decomposition(并查集)的更多相关文章
- HDU 5631 Rikka with Graph 暴力 并查集
		
Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...
 - 1320. Graph Decomposition
		
1320 简单并查集 #include <iostream> #include<cstdio> #include<cstring> #include<algo ...
 - 【XSY2469】graph 分治 并查集
		
题目大意 给你一张\(n\)个点\(m\)条边的无向图,问删去每个点后,原图是不是二分图. \(n,m\leq 100000\) 题解 一个图是二分图\(\Longleftrightarrow\)该图 ...
 - 2019.01.22 uoj#14. 【UER #1】DZY Loves Graph(并查集)
		
传送门 题意简述: 要求支持以下操作: 在a与b之间连一条长度为i的边(i是操作编号):删除当前图中边权最大的k条边:表示撤销第 i−1次操作,保证第1次,第i−1 次不是撤回操作. 要求在每次操作后 ...
 - Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 并查集
		
D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/ ...
 - hdu 5313 Bipartite Graph(dfs染色 或者 并查集)
		
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
 - Mr. Kitayuta's Colorful Graph 多维并查集
		
Mr. Kitayuta's Colorful Graph 并查集不仅可以用于一维,也可以用于高维. 此题的大意是10W个点10W条边(有多种颜色),10W个询问:任意两个节点之间可以由几条相同颜色的 ...
 - hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)
		
题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...
 - HDU 3726 Graph and Queries 平衡树+前向星+并查集+离线操作+逆向思维 数据结构大综合题
		
Graph and Queries Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
 
随机推荐
- sizeof和strlen区别
			
sizeof(...)是运算符,在头文件中typedef为unsigned int,其值在编译时即计算好了,参数可以是数组.指针.类型.对象.函数等 数组:编译时分配的空间大小 指针:指针所占的空间, ...
 - 【kate总结】Matlab坐标轴问题
			
[kate总结]Matlab坐标轴问题 总结而言 行óYó高ó垂直 列óXó宽ó水平 Maplab中存有2张图片 1.JPG 宽(列):320 高(行):482 在matlab中显示 2.JPG ...
 - 关于查询oracle in >1000 的讨论
			
https://q.cnblogs.com/q/88538/
 - IOS UTF8中文字母数字 组合时长度截取
			
//计算总共字数和限制字数的Index位置 -(NSMutableArray *) unicodeLengthOfString: (NSString *) text { NSMutableArray ...
 - Javascript 基础(二)
			
一.js运算符: +.-.*./.% %(去模 就是计算两个数的余数,通常判断是否能整除),主要用于整数. var a=90; var b=8; if(a%b==0) window.alert(&qu ...
 - 系统的 host文件的作用
			
有些用户可能已经注意到,我们在上网时除了可使用常规的 http://www.xxx.com或http://www.xxx.com.cn等形式的网站域名之外,还可以使用类似于“202.106.184.2 ...
 - 团队博客——Sprint计划会议1
			
每日Scrum:第一天 会议时间:4.14.晚八点半 会议地点:基础教学楼一楼大厅 小组成员:郭庆樑,林彦汝,张金 认领人—使团队成员分工合作,保持团队的积极性. ID 名称(NAME) 重要性(IM ...
 - 一维条形码攻击技术(Badbarcode)
			
0x00 前言 在日常生活中,条形码随处可见,特别在超市,便利店,物流业,但你们扫的条形码真的安全吗?之前TK教主 在PacSec介绍的条形码攻击和twitter上的demo视频太炫酷,所以就自己买了 ...
 - PHP中常用正则表达式大全
			
常用正则表达式大全!(例如:匹配中文.匹配html) 匹配中文字符的正则表达式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内 ...
 - iOS:Size Classes的使用
			
iOS 8在应用界面的可视化设计上添加了一个新的特性-Size Classes,对于任何设备来说,界面的宽度和高度都只分为两种描述:正常和紧凑.这样开发者便可以无视设备具体的尺寸,而是对这两类和它们的 ...