题目

分析

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

考虑一下树的定义,点数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. 自定义配置节点configSections的使用

    //App.config <?xml version="1.0" encoding="utf-8" ?><configuration>  ...

  2. Linux_OpenSSH远程连接

    目录 目录 SSH server SSH服务属性 SSH协议执行原理 SSH连接方式 ssh Commands scp commands sftp commands SSH在生产环境中的使用 系统间备 ...

  3. 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_02.三层架构和ssm框架的对应关系

  4. FLUME安装&环境(二):拉取MySQL数据库数据到Kafka

    Flume安装成功,环境变量配置成功后,开始进行agent配置文件设置. 1.agent配置文件(mysql+flume+Kafka) #利用Flume将MySQL表数据准实时抽取到Kafka a1. ...

  5. [Git] 015 远程仓库篇 第二话

    0. 前言 在 [Git] 006 在本地新建一个仓库 中,我在本地建了一个仓库 "git_note" 这回的任务 在 GitHub 上建一个远程仓库:为方便记忆,我就起名为 &q ...

  6. HashMap底层为什么一定用数组

    HashMap源码数据结构: Entry[] table = new Entry[capacity]; 其中,Entry就是一个链表节点.如果将数组替换成LinkedList是否可行?如下: List ...

  7. CentOS7创建本地源过程

    1)使用yum安装http服务(主节点) yum -y install httpd 2)将httpd服务加入系统自启动服务并设置开机启动 systemctl start httpd #启动apache ...

  8. 消息中间件 JMS入门

    1. JMS入门 1.1消息中间件 什么是消息中间件 消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,它可以在分布式环 ...

  9. 数塔 Medium

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  10. C语言中整形数组、字符数组、字符串的区别

    一. 第一 整型数组的存放,数组最后是不加'\0'的,字符串会自动加上,因此存放字符的时候数组的大小要比实际字符的多一个 第二 整型数组 每一个单元是4个字节的,字符串是一个一个字符存放的,每个字符占 ...