题目

分析

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

考虑一下树的定义,点数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. Apache监控调优

    apache是一款对静态资源处理得比较好的中间件,但是对动态请求处理得不是很好,tomcat则正好相反. apache运用得比较多得工作模式主要是Prefork和Worker两种模式 1.Prefor ...

  2. IDE引入mindmap插件,在项目中添加思维导图

    1.打开IDE,file--settings--plugins,搜索IDEA Mind Map 2.点击install,进行下载,然后按照提示restart重启IDEA,安装完成 3.创建mind m ...

  3. jmeter常用性能监听器分析

    jmeter中提供了很多性能数据的监听器,我们通过监听器可以来分析性能瓶颈 本文以500线程的阶梯加压测试结果来描述图表. 常用监听器 1:Transactions per Second 监听动态TP ...

  4. Redis的消息订阅及发布及事务机制

    Redis的消息订阅及发布及事务机制 订阅发布 SUBSCRIBE PUBLISH 订阅消息队列及发布消息. # 首先要打开redis-cli shell窗口 一个用于消息发布 一个用于消息订阅 # ...

  5. OSPF与ACL 综合应用

    1.企业内网运行OSPF路由协议,区域规划如图所示:2.财务和研发所在的区域不受其他区域链路不稳定性影响:3.R1.R2.R3只允许被IT登录管理:4.YF和CW之间不能互通,但都可以与IT互通:5. ...

  6. SSM框架之AOP、动态代理、事务处理相关随笔

    AOP: 原理:底层利用动态代理(两种动态代理技术都使用了) 两种实现方案: 第一种:JDK动态代理技术 实现的InvocationHandler接口,要想实现某个类的动态代理对象,必须有接口有实现类 ...

  7. AcWing 875. 快速幂

    题目链接:https://www.acwing.com/problem/content/description/877/ 快速幂模板题,计算ab mod p 的值,a,b,p大概1e9左右,可以快速计 ...

  8. js中箭头函数 及 针对箭头函数this指向问题引出的单体模式

    ES6允许使用“箭头”(=>)定义函数 var f = a = > a //等同于 var f = function(a){ return a; } 如果箭头函数不需要参数或需要多个参数, ...

  9. 小白学Python——Matplotlib 学习(3) 函数图形

    import matplotlib.pyplot as plt import numpy as np x = np.linspace(-1,1,50) y = 2*x + 1 plt.figure() ...

  10. onehot编码解释

    什么是One-Hot编码? One-Hot编码,又称为一位有效编码,主要是采用N位状态寄存器来对N个状态进行编码,每个状态都由他独立的寄存器位,并且在任意时候只有一位有效. One-Hot编码是分类变 ...