ACDream - Graphs
先上题目:
Graphs
Problem Description
Input
多组数据,每组数据N,M(0 <= N <= 10000,0 <= M <= 20000)
接下来M行每行给出一条边的两个端点x,y (1 <= x ,y <= N),保证无重边,无自环
Output
Sample Input
2 1
1 2
5 4
1 2
1 3
1 4
1 5
Sample Output
NO
YES 根据题意,我们可以将点分成3种:①度小于3的点,②度等于3的点,③度大于等于4的点。
对于①,我们可以直接跳过,因为这种点无论是单个还是组合都无法产生符合要求的子图。对于②,如果有两个度为三的点连载一起并且重合的点小于等于1个的话就有可能产生符合要求的子图。对于③,一个点就可以引出符合要求的子图。
所以我们可以先判断是否有③的点,如果有就直接输出YES,否则判断所有度为③的点是否有符合要求的,如果有就直接输出YES,否则就不存在题目要求的子图。 上代码:
#include <cstdio>
#include <cstring>
#define MAX 100002
using namespace std; int c[MAX][],p[MAX],d[MAX],a[MAX],co,n,m; int findset(int u){
return u==p[u] ? u : p[u]=findset(p[u]);
} bool check_(int x,int y){
int ans=;
for(int i=;i<;i++){
if(c[x][i]==y) ans++;
else{
for(int j=;j<;j++){
if(c[x][i]==c[y][j]) ans++;
}
}
}
return ans<=;
} bool check(){
co=;
for(int i=;i<n;i++){
if(d[i]>=) return ;
else if(d[i]==) a[co++]=i;
}
for(int i=;i<co;i++){
for(int j=i+;j<co;j++){
if(findset(a[i])==findset(a[j]) && check_(a[i],a[j])) return ;
}
}
return ;
} int main()
{
int u,v;
//freopen("data.txt","r",stdin);
while(scanf("%d %d",&n,&m)!=EOF){
for(int i=;i<=n;i++) p[i]=i;
memset(d,,sizeof(d));
for(int i=;i<m;i++){
scanf("%d %d",&u,&v);
if(d[u]<) c[u][d[u]]=v;
if(d[v]<) c[v][d[v]]=u;
d[u]++; d[v]++;
u = findset(u);
v = findset(v);
if(u!=v) p[v]=p[u];
}
if(check()) printf("YES\n");
else printf("NO\n");
}
return ;
}
Graphs
ACDream - Graphs的更多相关文章
- tunning-Instruments and Flame Graphs
On mac os, programs may need Instruments to tuning, and when you face too many probe messages, you'l ...
- Intel® Threading Building Blocks (Intel® TBB) Developer Guide 中文 Parallelizing Data Flow and Dependence Graphs并行化data flow和依赖图
https://www.threadingbuildingblocks.org/docs/help/index.htm Parallelizing Data Flow and Dependency G ...
- ACdream 1214---矩阵连乘
ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...
- acdream.LCM Challenge(数学推导)
LCM Challenge Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit ...
- acdream.Triangles(数学推导)
Triangles Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Stat ...
- acdream.A Very Easy Triangle Counting Game(数学推导)
A - A Very Easy Triangle Counting Game Time Limit:1000MS Memory Limit:64000KB 64bit IO Forma ...
- acdream.Bet(数学推导)
Bet Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Status Pra ...
- acdream.郭式树(数学推导)
郭式树 Time Limit:2000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit Status Pr ...
- ACdream 1188 Read Phone Number (字符串大模拟)
Read Phone Number Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Sub ...
随机推荐
- 20170322Linux
- arm下用shell控制gpio
创建脚本gpio.sh #!/bin/sh PIN=$ VALUE=$ if test -d /sys/class/gpio/gpio$PIN/ then echo $VALUE > /sys/ ...
- android中的back键处理
Back键是手机上的后退键,一般的软件不捕获相关信息可能导致你的程序被切换到后台,而回到桌面的尴尬情况,在Android上有两种方法来获取该按钮的事件. 1.直接获取按钮按下事件,此方法兼容Andro ...
- 二维矩阵相乘 in C++
#include <iostream> #include <vector> #include <string> #include <sstream> # ...
- openStack 主机流量计运行状态 随笔记录
root@ruiy-controller:~# ifconfigeth0 Link encap:Ethernet HWaddr 0c:c4:7a:0d:97:2c ine ...
- codevs1519 过路费(最小生成树+LCA)
1519 过路费 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 在某个遥远的国家里,有 n个城市.编号为 1,2 ...
- jquery中的left和top
left 和 top /*1. 获取元素基于定位容器的位置*/ /*返回的是对象 属性 left top */ var position = $('.inner').position(); conso ...
- vue-router简单用法
路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮 => home 内容, ...
- retrofit post请求多文件,partMap用法
1. APIService 定义注解 @Multipart @POST("cyxx/Feedback/add.do") Observable<ResponseBody> ...
- 对学Oracle数据库初学者的开场篇
前言:因为项目原因,近期开始学习Oracle数据库.Oracle是目前最流行的数据库之一,功能强大,性能卓越,相对的学习的难度还是不小.我打算将自己的学习过程记录下来,做个积累,方便自己和其他的学习者 ...