题目

分析

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

考虑一下树的定义,点数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);
}

【NOIP2016提高A组8.11】种树的更多相关文章

  1. 【NOIP2016提高A组8.11】自然数

    题目 分析 \(O(n)\)求出mex(1,i)(1<=i<=n): 虽然0<=ai<=10^9,但只有n个数,所以mex一定小于等于n for(long long j=1;j ...

  2. 【NOIP2016提高A组8.11】钱仓

    题目 分析 发现,一定有一个点作为起点,所有的路径都不经过这个起点. 接着贪心求答案, 如果\(c_i>1\),将其中\(c_i-1\)个钱往后"铺". 易证\(x^2+y^ ...

  3. JZOJ 【NOIP2016提高A组集训第16场11.15】兔子

    JZOJ [NOIP2016提高A组集训第16场11.15]兔子 题目 Description 在一片草原上有N个兔子窝,每个窝里住着一只兔子,有M条路径连接这些窝.更特殊地是,至多只有一个兔子窝有3 ...

  4. JZOJ 【NOIP2016提高A组集训第16场11.15】SJR的直线

    JZOJ [NOIP2016提高A组集训第16场11.15]SJR的直线 题目 Description Input Output Sample Input 6 0 1 0 -5 3 0 -5 -2 2 ...

  5. JZOJ 4732. 【NOIP2016提高A组模拟8.23】函数

    4732. [NOIP2016提高A组模拟8.23]函数 (Standard IO) Time Limits: 1500 ms  Memory Limits: 262144 KB  Detailed ...

  6. JZOJ 5462. 【NOIP2017提高A组冲刺11.8】好文章

    5462. [NOIP2017提高A组冲刺11.8]好文章 (File IO): input:article.in output:article.out Time Limits: 1000 ms  M ...

  7. 5458. 【NOIP2017提高A组冲刺11.7】质数

    5458. [NOIP2017提高A组冲刺11.7]质数 (File IO): input:prime.in output:prime.out Time Limits: 1000 ms  Memory ...

  8. JZOJ 5456. 【NOIP2017提高A组冲刺11.6】奇怪的队列

    5456. [NOIP2017提高A组冲刺11.6]奇怪的队列 (File IO): input:queue.in output:queue.out Time Limits: 1000 ms  Mem ...

  9. JZOJ 5459. 【NOIP2017提高A组冲刺11.7】密室

    5459. [NOIP2017提高A组冲刺11.7]密室 (File IO): input:room.in output:room.out Time Limits: 1000 ms  Memory L ...

随机推荐

  1. Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu

    Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu.TMenuItem.TMenuBar.TMainMenu 相关控件: TMenuBar.TPopup ...

  2. C语言的指针和数组

    指针和内存 指针变量也是个变量,不过保存的是另一个变量的地址.另外编译器还会记住指针所指向变量的类型,从而在指针运算时根据变量类型采取不同操作. 例如,char * a 定义了char 类型的指针变量 ...

  3. Python3 多线程编程 threading模块

    性能自动化测试除了用jmeter还可以用python threading模块做 一.threading模块定义 Python 2.4中包含的较新的线程模块为线程提供了更强大的高级支持. 线程模块公开线 ...

  4. 【HANA系列】SAP HANA SQL获取当前日期加若干天后的日期

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取当前 ...

  5. numpy2

    1.通用函数,是一种在ndarray数据中进行逐元素操作的函数.某些函数接受一个或多个标量数值,并产生一个或多个标量结果,通用函数就是对这些函数的封装. 1.常用的一元通用函数有:abs\fabs s ...

  6. Chapter03 第二节 const限定符的使用

    3.2 const限定符 const的作用:替代#define作为有类型检查的常量来使用.他的值被初始化后就固定了,成为一个只读变量,不能更改.(推荐使用特殊的命名规范来区分常量和非常量). cons ...

  7. 【Qt开发】V4L2 API详解 背景知识 打开设备设置参数

    www.linuxtv.org下,有篇文档详细讲解了V4L2相关知识和体系结构.是V4L2方面最全面的文档.可以通过它学习V4L2的一些思路和想法. http://www.linuxtv.org/do ...

  8. 【Linux开发】如何更改linux文件的拥有者及用户组(chown和chgrp)

    本文整理自: http://blog.163.com/yanenshun@126/blog/static/128388169201203011157308/ http://ydlmlh.iteye.c ...

  9. kafka producer发送消息 Failed to update metadata after问题

    提示示例: ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: Fail ...

  10. Javascript原型介绍

    原型及原型链 原型基础概念 function Person () { this.name = 'John'; } var person = new Person(); Person.prototype ...