题目

分析

题目要求把图删点,删成树。

考虑一下树的定义,点数n=边数m+1

并且,树中点两两之间联通,那么选的点就不能是割点。

可以用tarjan将图中最大的联通块,保证其中点两两之间有不止一条路径来联通。

那么保证这个联通块中向外界联通的点一定是割点。

求出最大的联通块后,每个点判读一下就可以了。

#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
const int maxlongint=2147483647;
const int mo=1000000007;
const int N=101000;
using namespace std;
int n,m,low[N],dfn[N],last[N],next[N*2],to[N*2],tot,d[N],b[N],dd;
bool bz[N],part[N];
int bj(int x,int y)
{
next[++tot]=last[x];
last[x]=tot;
to[tot]=y;
}
int tarjan(int x,int fa)
{
dfn[x]=low[x]=++dd;
d[++tot]=x;
bz[x]=false;
for(int i=last[x];i;i=next[i])
{
int j=to[i];
if(fa!=j)
{
if(bz[j])
{
tarjan(j,x);
low[x]=min(low[x],low[j]);
}
else
low[x]=min(low[x],low[j]);
}
}
if(dfn[x]==low[x])
{
if(d[tot]==x)
tot--;
else
while(dfn[d[tot]]>=dfn[x])
{
part[d[tot--]]=true;
}
}
}
int main()
{
memset(bz,true,sizeof(bz));
scanf("%d%d",&n,&m);
if(m==n-1)
{
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
b[x]++;
b[y]++;
}
int ans=0;
for(int i=1;i<=n;i++)
if(b[i]==1)
ans++;
printf("%d\n",ans);
for(int i=1;i<=n;i++)
if(b[i]==1)
printf("%d ",i);
return 0;
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
bj(x,y);
bj(y,x);
}
for(int i=1;i<=n;i++)
{
if(!last[i])
{
printf("1\n%d",i);
return 0;
}
}
tot=0;
tarjan(1,0);
memset(bz,false,sizeof(bz));
int ans=0;
for(int i=1;i<=n;i++)
{
if(part[i])
{
bz[i]=true;
int sum=0;
for(int j=last[i];j;j=next[j])
{
if(!part[to[j]])
{
bz[i]=false;
break;
}
else sum++;
}
if(m-sum+1!=n-1) bz[i]=false;
if(bz[i]) ans++;
}
}
printf("%d\n",ans);
for(int i=1;i<=n;i++)
if(bz[i])
printf("%d ",i);
}

最新文章

  1. Atittit.研发公司的组织架构与部门架构总结
  2. .Net开源微型ORM框架测评
  3. FtpDataStream中的隐藏问题
  4. C#简单问题,不简单的原理:不能局部定义自定义类型(不含匿名类型)
  5. 浅谈Java五大设计原则之观察者模式
  6. Ubuntu系统安装(win7双系统)
  7. logging模块转载博客
  8. ural 1247. Check a Sequence
  9. HP StorageWorks MSL2024 Tape Libraries - Tape library Error Codes
  10. CSS:static/relative/absolute
  11. jsCodeWar 多函数嵌套调用
  12. Android Source Code
  13. java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏
  14. android 快速创建一个新的线程
  15. .Net 2.0实例学习:WebBrowser页面与WinForm交互技巧
  16. 怎么在linux Ubuntu上部署nodejs
  17. Codeforces Round #398 (div.2)简要题解
  18. Netty源码分析(四):EventLoopGroup
  19. 21.命名空间别名限定符::和global全局名称空间限定符
  20. Python 的xlutils模块

热门文章

  1. [转]delphi 防止刷新时闪烁的终极解决办法
  2. GitHub入门(一)GIT配置与Hexo博客搭建
  3. C#学习基础
  4. 关于win10系统如何调用debug查看CPU汇编指令和内存
  5. 【MM系列】SAP MRKO如何操作
  6. cocos2dx基础篇(13) 编辑框之二CCEditBox
  7. 操作系统 - Windows操作系统 - WindowsXP - 安装|命令|使用 - 汇总
  8. 【Linux开发】将cmd中命令输出保存为TXT文本文件
  9. [转帖]CBO和RBO
  10. [19/09/16-星期一] Python的运算符和条件判断语句