先上题目:

Graphs

Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

Problem Description

给出N个点,M条边,问是否存在一个连通子图,子图由原图删掉一些点和边(不删亦可),且叶子数>=4(即度为1的点)

Input

多组数据,每组数据N,M(0 <= N <= 10000,0 <= M <= 20000)

接下来M行每行给出一条边的两个端点x,y (1 <= x ,y <= N),保证无重边,无自环

Output

对于每组数据,输出YES,如果你能找到这样的子图,否则输出NO

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的更多相关文章

  1. tunning-Instruments and Flame Graphs

    On mac os, programs may need Instruments to tuning, and when you face too many probe messages, you'l ...

  2. 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 ...

  3. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  4. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  5. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  6. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  7. acdream.Bet(数学推导)

    Bet Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  8. acdream.郭式树(数学推导)

    郭式树 Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Pr ...

  9. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

随机推荐

  1. bzoj4078

    二分+2-sat 枚举第一个权值,二分第二个权值,然后2-sat检查,当第一个权值已经不能形成二分图时,再往下没意义,因为没法分成两个点集.(双指针好像跑得慢) #include<bits/st ...

  2. 最新昆石VOS2009/VOS3000手机号段导入文件(手机归属地)

    使用2017年4月最新版手机号段归属地制作,支持所有版本的VOS 共360569条记录,兼容所有版本的昆石VOS,包括VOS2009.vos3000.vos5000 导入比较简单.下载后解压到桌面在V ...

  3. PCB 奥宝LDI 输出自动改周期检测内容

    继续完善奥宝LDI输出,在自动更新周期发现前期梳理不过完善或出些从未考虑到的工艺问题, 今天将更改线路周期检测内容整理如下

  4. APP加固反调试(Anti-debugging)技术点汇总

    0x00 时间相关反调试 通过计算某部分代码的执行时间差来判断是否被调试,在Linux内核下可以通过time.gettimeofday,或者直接通过sys call来获取当前时间.另外,还可以通过自定 ...

  5. 工具分享2:Python 3.6.4、文本编辑器EditPlus、文本编辑器Geany

    工具官网下载地址: https://www.python.org/downloads/ python 3.6.0下载链接: 链接:https://pan.baidu.com/s/1snuSxsx 密码 ...

  6. BZOJ 2101 DP+优化

    思路: http://www.cnblogs.com/exponent/archive/2011/08/14/2137849.html f[i,i+len]=sum[i,i+len]-min(f[i+ ...

  7. invoke与call

    “调用一个委托实例” 中的 “调用” 对应的是invoke,理解为 “唤出” 更恰当.它和后面的 “在一个对象上调用方法” 中的 “调用” 稍有不同,后则对应的是call.在英语的语境中,invoke ...

  8. .net core2.0 自定义中间件

    一.中间件(Middleware) 中间件是被组装成一个应用程序管道来处理请求和响应的软件组件. 二.编写SimpleMiddleware using Microsoft.AspNetCore.Htt ...

  9. web通信之跨文档通信 postMessage

    index.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  10. 2.0 Linux系统的安装之Fedora安装单系统(2)

    2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...