1320. Graph Decomposition

Time limit: 0.5 second
Memory limit: 64 MB
There
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

contains
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

“1” (without quotation marks), if the decomposition is possible and “0” otherwise.

Samples

input output
1 2
2 3
3 1
1 10
1
1 2
2 3
3 1
4 10
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(并查集)的更多相关文章

  1. HDU 5631 Rikka with Graph 暴力 并查集

    Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...

  2. 1320. Graph Decomposition

    1320 简单并查集 #include <iostream> #include<cstdio> #include<cstring> #include<algo ...

  3. 【XSY2469】graph 分治 并查集

    题目大意 给你一张\(n\)个点\(m\)条边的无向图,问删去每个点后,原图是不是二分图. \(n,m\leq 100000\) 题解 一个图是二分图\(\Longleftrightarrow\)该图 ...

  4. 2019.01.22 uoj#14. 【UER #1】DZY Loves Graph(并查集)

    传送门 题意简述: 要求支持以下操作: 在a与b之间连一条长度为i的边(i是操作编号):删除当前图中边权最大的k条边:表示撤销第 i−1次操作,保证第1次,第i−1 次不是撤回操作. 要求在每次操作后 ...

  5. 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/ ...

  6. hdu 5313 Bipartite Graph(dfs染色 或者 并查集)

    Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...

  7. Mr. Kitayuta's Colorful Graph 多维并查集

    Mr. Kitayuta's Colorful Graph 并查集不仅可以用于一维,也可以用于高维. 此题的大意是10W个点10W条边(有多种颜色),10W个询问:任意两个节点之间可以由几条相同颜色的 ...

  8. hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)

    题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...

  9. HDU 3726 Graph and Queries 平衡树+前向星+并查集+离线操作+逆向思维 数据结构大综合题

    Graph and Queries Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. socket编程概述

    一.基本流程如下: 整个TCP过程非常类似于电话系统.TCP是有两个不同主机上的进程需要进行通信,电话系统是有两个人位于不同地区的人需要进行通信. socket:获得可用于进程通信的端点.由于Linu ...

  2. Controller方法的返回值

    方法的返回值1.ModelAndView这个就不多说,这是最基础的,前面定义一个ModelAndView,中途使用addObject方法添加属性,再返回.视图解析器会自动扫描到的.2.String这个 ...

  3. 《J2EE,J2SE,J2ME》

    J2EE(Java EE)是做企业级应用的.比如,163邮箱,比如某公司的管理系统 J2SE(Java SE)就是Java语言的标准版本,类似于C++,主要做桌面软件,比如Eclipse,MyEcli ...

  4. Event Handling on Mac

    Keyboard/Mouse Event + Cocoa AppleEvent + Cocoa AppleEvent + CommandLine App(w/o UI) + CoreFoundatio ...

  5. poj2891 拓展欧几里得

    //Accepted 164 KB 16 ms //拓展欧几里得 //m=a1*x+b1 --(1) //m=a2*(-y)+b2 --(2) //->a1*x+a2*y=b2-b1 //由欧几 ...

  6. operation not possible due to RF-kill

    使用mdk3时出现这个问题operation not possible due to RF-kill 就是输入第一条命令 后出现 operation not possible due to RF-ki ...

  7. 在国内时,更新ADT时需要配置的

    RT

  8. IOS 作业项目(4)步步完成 画图 程序(问题处理)终结

    一,解决换色程序崩溃问题 程序崩溃是因为颜色的内存被释放,添加如下类的内容即可 @implementation TuyaPath - (id)init { self = [super init]; i ...

  9. Juniper SRX防火墙-NAT学习笔记!

    Junos NAT第一部分:SRX NAT介绍第二部分:Source NAT:Interface NAT第三部分:Source NAT:Address Pools第四部分:Destination NA ...

  10. Gmail邮箱添加域名解析

    主机记录  MX   服务器地址 优先级@  MX   ASPMX.L.GOOGLE.COM. 10@  MX   ALT1.ASPMX.L.GOOGLE.COM. 20@  MX   ALT2.AS ...