题目

分析

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

考虑一下树的定义,点数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. Python基本语法_异常处理详解

    目录 目录 异常 异常类型 异常处理 触发异常raise 传递异常 assert语句触发异常 捕获异常tryexceptelse 捕捉多个异常 tryfinally语句 自定义异常 withas触发异 ...

  2. Delphi XE2 之 FireMonkey 入门(36) - 控件基础: TForm

    Delphi XE2 之 FireMonkey 入门(36) - 控件基础: TForm 当我第一次读取 Form1.StyleLookup 并期待出现 "formstyle" 时 ...

  3. 【漏洞学习】HOST 头攻击漏洞

    日期:2018-03-06 14:32:51 作者:Bay0net 0x01. 前言 在一般情况下,几个网站可能会放在同一个服务器上,或者几个 web 系统共享一个服务器,host 头来指定应该由哪个 ...

  4. 【命令汇总】Windows 应急响应

    日期:2019-06-07 16:11:49 作者:Bay0net 介绍:Windows 应急响应.取证及溯源相关内容学习记录 0x00.前言 常见的应急分类: web入侵:网页挂马.主页篡改.Web ...

  5. Java使用JDBC连接Impala

    前段时间,有一个项目在连接Impala的时候,可以测试连接成功,但是查询不出表.但是通过impala-shell的时候,是可以查询出来的,我觉的这种方式查询出来的话,可能和jdbc的方式不一样,因为i ...

  6. delphi2010:按键 控制键 组合键的判断 响应

    procedure TForm7.FormShortCut(var Msg: TWMKey; var Handled: Boolean); var   aKey: TShortCut;   aShif ...

  7. Nginx 配置文件 nginx.conf 详解

    Nginx的配置文件nginx.conf配置详解如下: user nginx nginx; #Nginx用户及组:用户 组.window下不指定 worker_processes 8; #工作进程:数 ...

  8. 【VS开发】C++调用外部程序

    关于三个SDK函数:WinExec, ShellExecute,CreateProcess的其他注意事项:[1]定义头文件必须定义以下两个头文件: [cpp] view plain copy #inc ...

  9. JSP页面读取数据中的数据内容,出现乱码现象的解决方法

    1.首先要确保JSP页面的编码已修改为“utf-8”的字符编码: 2.然后再在jsp页面上添加代码进行设置: 先用getBytes()方法读出数据,然后再new String()方法设置格式为“utf ...

  10. shell学习笔记1---shell编程基础

    Shell是什么? Shell 是一个应用程序,它连接了用户和 Linux 内核,让用户能够更加高效.安全.低成本地使用 Linux 内核,这就是 Shell 的本质. Shell 本身并不是内核的一 ...