#67. 新年的毒瘤

辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树。

这个长着毒瘤的树可以用n个结点m 条无向边的无向图表示。这个图中有一些结点被称作是毒瘤结点,即删掉这个结点和与之相邻的边之后,这个图会变为一棵树。树也即无简单环的无向连通图。

现在给你这个无向图,喜羊羊请你帮他求出所有毒瘤结点。

样例一

input

6 6
1 2
1 3
2 4
2 5
4 6
5 6

output

3
4 5 6 256MB

来源

UOJ Goodbye Jiawu

【思路】

无向图的割顶。

如果剩下的点组成一棵树,则满足边数为n-2。

   那么“毒瘤”满足:1/非割顶;2/度数=m-(n-2)。

【代码】

 #include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
using namespace std; const int maxn = +; int pre[maxn],low[maxn],iscut[maxn],dfs_clock;
vector<int> G[maxn]; int dfs(int u,int fa) {
int lowu=pre[u]=++dfs_clock;
int ch=;
for(int i=;i<G[u].size();i++) {
int v=G[u][i];
if(!pre[v]) {
ch++;
int lowv=dfs(v,u);
lowu=min(lowu,lowv);
if(lowv>=pre[u]) iscut[u]=; //只要有一个
}
else if(pre[v]<pre[u] && v!=fa) {
lowu=min(lowu,pre[v]);
}
}
if(fa< && ch==) iscut[u]=;
low[u]=lowu;
return lowu;
} int read() {
char c=getchar();
while(!isdigit(c)) c=getchar();
int x=;
while(isdigit(c))
x=x*+c-'' , c=getchar();
return x;
} int n,m;
int d[maxn],ans[maxn]; int main() {
n=read(),m=read();
int u,v;
for(int i=;i<m;i++) {
u=read(),v=read();
u--,v--;
d[u]++,d[v]++;
G[u].push_back(v),G[v].push_back(u);
}
dfs(,-);
int tot=;
for(int i=;i<n;i++)
if(!iscut[i] && d[i]==m-(n-))
ans[tot++]=i+;
printf("%d\n",tot);
for(int i=;i<tot;i++) printf("%d ",ans[i]);
return ;
}

uoj#67. 新年的毒瘤(割顶)的更多相关文章

  1. uoj 67 新年的毒瘤 tarjan求割点

    #67. 新年的毒瘤 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/67 Description 辞旧迎新之际 ...

  2. uoj 67 新年的毒瘤 割点

    题目链接: 题目 #67. 新年的毒瘤 问题描述 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树. 这个长着毒瘤的树可以用 nn 个结点 mm 条无向边的无向图表示.这个图中有 ...

  3. UOJ#67. 新年的毒瘤

    传送门 练习一下Tarjan的模板. 求一下割点,然后加个约束条件判一下特殊点,剩下的就是所求点. //UOJ 67 //by Cydiater //2016.10.27 #include <i ...

  4. uoj#67 新年的毒瘤【Tarjan】

    题目:http://uoj.ac/problem/67 题意:n个节点m条边的图,删除某个节点及他相连的所有边之后,剩下的图就成了一棵树.找出所有这样的节点. 思路:上次去清华面试的B题,当时就是在瞎 ...

  5. UOJ 67 新年的毒瘤 - Tarjan

    Description 给出一个无向图, 要求找出某个点$u$, 去掉$u$和$u$所连的边, 所剩下的节点构成一棵树. Solution 首先, 割点肯定是不可能满足条件的, 因为去掉割点后会构成若 ...

  6. 【UOJ】67 新年的毒瘤 &【BZOJ】1123 BLO

    [UOJ 67] 题目链接: 传送门 题解: 第一眼很懵逼……这什么鬼. 思考什么点复合条件……(o(>﹏<)o 1.树,也就是说还剩n-2条边,等价于要删去一个度数为m-n+2的点. 2 ...

  7. 【UOJ#67】新年的毒瘤 Tarjan 割点

    #67. 新年的毒瘤 UOJ直接黏贴会炸...    还是戳这里吧: http://uoj.ac/problem/67#tab-statement Solution 看到这题的标签就进来看了一眼. 想 ...

  8. 【UOJ#67】新年的毒瘤(Tarjan)

    [UOJ#67]新年的毒瘤(Tarjan) 题面 UOJ 题解 一棵\(n\)个节点的树显然有\(n-1\)条边,在本题中意味着删去一个点之后还剩下\(n-2\)条边.那么找到所有度数为\(m-(n- ...

  9. UOJ67 新年的毒瘤【Tarjan,割点】

    Online Judge:#uoj 67 Label:Tarjan,割点,细节 题目描述 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树.这个长着毒瘤的树可以用\(n\)个结点 ...

随机推荐

  1. datagrid后台给每列添加js方法

    protected void dgExhList_ItemDataBound(object sender, DataGridItemEventArgs e) { string param = &quo ...

  2. Css3渐变实例Demo(一)

    1.指定渐变背景的大小 .div { background: url(../img/1.jpg); /*background-size:contain;*/ width: 500px; height: ...

  3. ST3破解命令

      open terminal and input it!   printf '\x39' | dd seek=$((0x6f35)) conv=notrunc bs=1 of=/Applicatio ...

  4. oracle还原数据库及遇到的问题

    1. 第一:用安装数据库时的管理员用户登录:创建一个新的用户,如: //创建用户123密码456 create user 123 identified by 456;第二:授权,赋予dba的权限 gr ...

  5. CI 笔记(easyui js命令)

    1. 两种方式加载easyui,一是用class自动渲染,一种是js.建议js. 2. 参考李炎恢的easyui的视频教程.最好的一个视频,对于easyui.

  6. 数字证书文件cer和pfx的区别

    作为文件形式存在的证书一般有这几种格式: 1.带有私钥的证书 由Public Key Cryptography Standards #12,PKCS#12标准定义,包含了公钥和私钥的二进制格式的证书形 ...

  7. Elasticsearch学习2--Elasticsearch数据类型简介

    1.Elasticsearch 是 面向文档型数据库,这意味着它存储的是整个对象或者 文档,它不但会存储它们,还会为他们建立索引,这样你就可以搜索他们了.你可以在 Elasticsearch 中索引. ...

  8. Codeforces 543C Remembering Strings(DP)

    题意比较麻烦 见题目链接 Solution: 非常值得注意的一点是题目给出的范围只有20,而众所周知字母表里有26个字母.于是显然对一个字母进行变换后是不影响到其它字符串的. 20的范围恰好又是常见状 ...

  9. 【HDU4010】【LCT】Query on The Trees

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  10. 【ZOJ2112】【整体二分+树状数组】带修改区间第k大

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...