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. Program A - 暴力求解

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  2. SharePoint 2013 开发——APP安全模型

    博客地址:http://blog.csdn.net/FoxDave 除非开启了SharePoint网站的匿名访问,否则对于入站的请求,必须要有一个身份验证的过程(Authentication),这个 ...

  3. Tarjan算法求有向图的强连通分量

    算法描述 tarjan算法思想:从一个点开始,进行深度优先遍历,同时记录到达该点的时间(dfn记录到达i点的时间),和该点能直接或间接到达的点中的最早的时间(low[i]记录这个值,其中low的初始值 ...

  4. Ubuntu 14.10 下安装MySQL

    在Ubuntu上安装MySQL很简单,只需要几个命令行 1 安装服务器 sudo apt-get install mysql-server 2 安装客户端 sudo apt-get install m ...

  5. Actipro Ribbon For WPF 界面控件免费下载地址

    Actipro Ribbon可以添加ribbon用户界面到你的程序中,功能包含:ribbon大小调整.程序菜单.QAT.嵌入的多种控件.多种布局选项.按键提示.屏幕提示.WPF命令模式用法.多种样式. ...

  6. 极客DIY:打造属于自己的无线移动渗透测试箱

    本文中介绍的工具.技术带有一定的攻击性,请合理合法使用. 你想不想拥有一款属于自己的移动无线渗透测试箱,如果你感兴趣,下面介绍的设备将会对你很有帮助.这个箱子被称为“MiTM(中间人攻击)WiFi箱” ...

  7. Android.mk 常用宏和变量

    android ndk开发有一个重要的文件 Android.mk,他虽然重要,但是对它进行深入介绍的文档却比较的少,这里将对Android.mk中常用的宏和变量进行说明: 由于这一部分的内容多,资料零 ...

  8. BZOJ 3165 Segment

    同上题. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...

  9. [Camel Basics]

    Define routes: Either using Spring xml or Java DSL. Spring xml: <camelContext> <routeBuilde ...

  10. POJ2449 (k短路)

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...