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 ...
随机推荐
- POJ 1845 求a^b的约数和
题目大意就是给定a和b,求a^b的约数和 f(n) = sigma(d) [d|n] 这个学过莫比乌斯反演之后很容易看出这是一个积性函数 那么f(a*b) = f(a)*f(b) (gcd(a,b) ...
- Visual Studio安装过程
在这里需要先跟老师说一声抱歉,因为编写代码的愿意,我早在大一的时候就已经安装并且购买了正版的VS2013.所以今天在这里实在无法全部描述VS2013的安装过程. 然而,我所知的是,VS2013相对于我 ...
- object_c函数多个返回值
- (void)readStr1:(NSString**)str1 andStr2:(NSString**)str2{ NSString *s1 = @"1"; NSS ...
- C#基础--面向过程计算器
//面向过程计算器 //思路: 需要注意的是: 两个数相除 除数不能为0: //1.提示用户输入 //2.进行运算 //3.得到结果 Console.WriteLine("请输入第一个数字: ...
- comet
comet 1.简介: 基于 HTTP长连接的“服务器推”技术,是一种新的 Web 应用架构,基于这种架构开发的应用中,服务器端会主动以异步的方式向客户端程序推送数据,而不需要客户端显式的发出请求.C ...
- 一个简单的Dump转文本工具—Dump2Text
每次电脑重装都得烦心,要把庞大的IDE重新配置一次,正准备安装Visual Stdio 2010,上网找镜像的时候发现,Visual Stdio 2013推出了Community版,不仅没有lite掉 ...
- Intellij导入外部的jar
File -> Project Structure (ctrl + shift + alt + s ) -> Module -> Dependencies -> Add... ...
- Interview----将一棵二叉树转换成其镜像
题目:输入一颗二元查找树,将该树转换为它的镜像, 即在转换后的二元查找树中,左子树的结点都大于右子树的结点. 用递归和循环两种方法完成树的镜像转换. 例如输入: 8 / ...
- How to set up a basic working Appium test environment
Appium is a test framework targeting devices; although it is very handy and powerful, it is not so s ...
- CoreData的使用入门到精通
源码下载地址: http://download.csdn.net/download/huntaiji/6664567 一,创建项目文件--选择Empty Application 起名:CoreDat ...