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 ...
随机推荐
- POJ2559 Largest Rectangle in a Histogram 单调栈
题目大意 有一个直方图,其所有矩形的底均是1(以后简称小矩形).给出这些矩形的高度,求这些矩形的并集中存在的面积最大的矩形(简称大矩形)的面积. 题解 大矩形的高必然一边等于一个小矩形的高,另一边小于 ...
- bzoj4737: 组合数问题
终于过了肝了一天啊,怎么我最近都在做细节码农题啊 (这种水平NOIP凉凉??) luacs大家都可以想到用吧,一开始我的思路是把所有在p以内的%p==0的组合数预处理出来,那C(n/p,m/p)任取, ...
- [POJ 1041] John's Trip
[题目链接] http://poj.org/problem?id=1041 [算法] 欧拉回路[代码] #include <algorithm> #include <bitset&g ...
- yii 面包屑
Yii的Breadcrumbs 是Yii的路径插件,使用方法: <?php $this->widget('zii.widgets.CBreadcrumbs', array('links'= ...
- 洛谷P2916 [USACO08NOV]为母牛欢呼(最小生成树)
P2916 [USACO08NOV]为母牛欢呼Cheering up the C… 题目描述 Farmer John has grown so lazy that he no longer wants ...
- Cracking the Coding Interview 6.5
There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. If it ...
- chapter6 数据结构基础之习题 Parentheses Balance
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- C - Between the Offices
Problem description As you may know, MemSQL has American offices in both San Francisco and Seattle. ...
- 一种压缩图片的方法---Machine learning 之 K-Means
背景描述: RGB编码:对于一个直接用24bit表示每一个而像素的图像来说,每一个pixel使用8-bit无符号整数(0-255)来表示红or绿or蓝. 压缩目的: 将128x128大小的图片由原来的 ...
- sql 添加列并设置默认值
ALTER TABLE tablsename ADD fieldname BIT NULL DEFAULT