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. Rhel6-hadoop分布式部署配置文档

    理论基础: Hadoop 分布式文件系统架构 HDFS 负责大数据存储 MapReduce 负责大数据计算 namenode  master守护进程 datanode  slaves上负责存储的进程 ...

  2. SharePoint加K2,将Portal系统与BPM系统完美整合!

    K2 blackPearl与Microsoft Office SharePoint 一起为解决人员和流程相互合作的解决方案而提供一个强大的平台. K2“blackpearl”根据企业的需求提供了设计, ...

  3. Oracle常用的函数

    1.常用的函数分为五大类: 字符函数.数字和日期函数.数字函数.转换函数.混合函数 2.字符函数 字符函数主要用于修改字符列.这些函数接受字符输入,返回字符或数字值.Oracle 提供的一些字符函数如 ...

  4. Visual Studio安装过程

    在这里需要先跟老师说一声抱歉,因为编写代码的愿意,我早在大一的时候就已经安装并且购买了正版的VS2013.所以今天在这里实在无法全部描述VS2013的安装过程. 然而,我所知的是,VS2013相对于我 ...

  5. vSphere Client上传镜像

    1. 使用vSphere Client连接到VMware ESXI 2. 打开右侧 [摘要] 选项卡 3. 在 [资源] 中选择存储器中的存储,右键 [浏览数据库存储] 4. 选择工具栏 [创建新文件 ...

  6. Mahout0.9的安装与测试

    最近想实协同过滤的MR算法,但是网上查了一下,发现hadoop的生态系统中的Mahout的项目已经实现了相应的算法,因此想先尝试着实时这个mahout的使用及效果.要想用mahout必须要部署到had ...

  7. php 封装分页查询类

    <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

  8. 多数求和(java)

    实验题目:从命令行接受多个数字,求和之后输出结果. 设计思想:命令行输入的字符会赋值给args数组,所以在命令行输入数字后,直接取出args的数组长度,作为循环语句的终点判断,然后利用循环将字符型改为 ...

  9. JAVA的第一个程序

    关于下载安装环境变量的配置网上的教程已经很多了 . 下面附上第一个HelloWorld的代码 /** 这是我的第一个java程序 */ public class HelloWorld { public ...

  10. 钱币兑换问题_完全背包&&拆分&&母函数

    ps:原来用新浪,可是代码的排版不是很好,所以用博客园啦,先容许我把从八月份开始的代码搬过来,从这里重新出发,希望这里可以一直见证我的成长. Time Limit: 2000/1000 MS (Jav ...