传送门

练习一下Tarjan的模板。

求一下割点,然后加个约束条件判一下特殊点,剩下的就是所求点。

//UOJ 67
//by Cydiater
//2016.10.27
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <cstdio>
#include <bitset>
#include <cstdlib>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define cmin(a,b) a=min(a,b)
#define cmax(a,b) a=max(a,b)
const int MAXN=2e5+5;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int N,M,LINK[MAXN],len=0,dfn[MAXN],low[MAXN],dfs_clock=0,siz[MAXN],ans=0,outdu[MAXN];
bool vis[MAXN],OK[MAXN];
struct edge{
	int y,next;
}e[MAXN];
namespace solution{
	inline void insert(int x,int y){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;}
	void init(){
		N=read();M=read();
		up(i,1,M){
			int x=read(),y=read();
			insert(x,y);
			insert(y,x);
			siz[x]++;siz[y]++;
		}
	}
	void tarjan(int node,int father){
		vis[node]=1;dfn[node]=low[node]=++dfs_clock;
		for(int i=LINK[node];i;i=e[i].next)if(e[i].y!=father){
			if(!dfn[e[i].y]){
				outdu[node]++;
				tarjan(e[i].y,node);
				cmin(low[node],low[e[i].y]);
				if(low[e[i].y]>=dfn[node])OK[node]=1;
			}else if(vis[e[i].y]) cmin(low[node],dfn[e[i].y]);
		}
		if(M-siz[node]!=N-2)OK[node]=1;
		if(outdu[node]==1&&node==1&&M-siz[node]==N-2)OK[node]=0;
		if(OK[node])ans++;
	}
	void slove(){
		up(i,1,N)if(!dfn[i])tarjan(i,0);
	}
	void output(){
		cout<<N-ans<<endl;
		up(i,1,N)if(!OK[i])printf("%d ",i);
	}
}
int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	init();
	slove();
	output();
	return 0;
}

UOJ#67. 新年的毒瘤的更多相关文章

  1. uoj#67. 新年的毒瘤(割顶)

    #67. 新年的毒瘤 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树. 这个长着毒瘤的树可以用n个结点m 条无向边的无向图表示.这个图中有一些结点被称作是毒瘤结点,即删掉这个结 ...

  2. uoj 67 新年的毒瘤 tarjan求割点

    #67. 新年的毒瘤 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/67 Description 辞旧迎新之际 ...

  3. uoj 67 新年的毒瘤 割点

    题目链接: 题目 #67. 新年的毒瘤 问题描述 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树. 这个长着毒瘤的树可以用 nn 个结点 mm 条无向边的无向图表示.这个图中有 ...

  4. uoj#67 新年的毒瘤【Tarjan】

    题目:http://uoj.ac/problem/67 题意:n个节点m条边的图,删除某个节点及他相连的所有边之后,剩下的图就成了一棵树.找出所有这样的节点. 思路:上次去清华面试的B题,当时就是在瞎 ...

  5. UOJ 67 新年的毒瘤 - Tarjan

    Description 给出一个无向图, 要求找出某个点$u$, 去掉$u$和$u$所连的边, 所剩下的节点构成一棵树. Solution 首先, 割点肯定是不可能满足条件的, 因为去掉割点后会构成若 ...

  6. 【UOJ】67 新年的毒瘤 &【BZOJ】1123 BLO

    [UOJ 67] 题目链接: 传送门 题解: 第一眼很懵逼……这什么鬼. 思考什么点复合条件……(o(>﹏<)o 1.树,也就是说还剩n-2条边,等价于要删去一个度数为m-n+2的点. 2 ...

  7. 【UOJ#67】新年的毒瘤 Tarjan 割点

    #67. 新年的毒瘤 UOJ直接黏贴会炸...    还是戳这里吧: http://uoj.ac/problem/67#tab-statement Solution 看到这题的标签就进来看了一眼. 想 ...

  8. 【UOJ#67】新年的毒瘤(Tarjan)

    [UOJ#67]新年的毒瘤(Tarjan) 题面 UOJ 题解 一棵\(n\)个节点的树显然有\(n-1\)条边,在本题中意味着删去一个点之后还剩下\(n-2\)条边.那么找到所有度数为\(m-(n- ...

  9. UOJ67 新年的毒瘤【Tarjan,割点】

    Online Judge:#uoj 67 Label:Tarjan,割点,细节 题目描述 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树.这个长着毒瘤的树可以用\(n\)个结点 ...

随机推荐

  1. SQL SERVER 2008:内部查询处理器错误: 查询处理器在执行过程中遇到意外错误

       今天一个同事突然告诉我,以前跑得很正常的一个SQL语句,执行时突然报如下错误:         消息1222,级别16,状态18,第1 行         已超过了锁请求超时时段.        ...

  2. Linux命令学习总结:dos2unix - unix2dos

    命令简介: dos2unix是将Windows格式文件转换为Unix.Linux格式的实用命令.Windows格式文件的换行符为\r\n ,而Unix&Linux文件的换行符为\n. dos2 ...

  3. Swift实现封装PopMenu菜单,可在屏幕任意位置弹出

    效果图: 说明: 代码现已支持 Swift3 语法 使用介绍: 1.初始化位置 //frame 为整个popview相对整个屏幕的位置 箭头距离右边位置,默认15 //popMenu = SwiftP ...

  4. linux中通配符和常用特殊符号

    1 通配符   2 特殊符号 3 参考文档 鸟哥的私房菜 http://vbird.dic.ksu.edu.tw/linux_basic/0320bash_4.php#settings_wildcar ...

  5. localhost与127.0.0.1的区别

    localhost与127.0.0.1的区别是什么 定义 localhost也叫local ,正确的解释是:本地服务 127.0.0.1在windows等系统的正确解释是:本机地址(本机服务器) 不同 ...

  6. hdfs 通过NFSV3 加载至本地目录

    常常会有这种需求,把HDFS的目录MOUNT到本地目录,然后方便使用LINUX下面的命令直接操作. FUSE也可以达到同样的效果,但是配置比较复杂,新的HADOOP版本都建议使用NFS3来完成这个需求 ...

  7. java笔记

    ANT概述:http://www.blogjava.net/amigoxie/archive/2007/11/09/159413.html http://baitai.iteye.com/blog/7 ...

  8. Core 开发-Logging 使用NLog

    ASP.NET Core 开发-Logging 使用NLog 写日志文件   ASP.NET Core 开发-Logging 使用NLog 写日志文件. NLog 可以适用于 .NET Core 和 ...

  9. HashMap实现原理及源码分析

    哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表,而HashMap的实现原理也常常出 ...

  10. markdown编辑器

    经过一番探索终于找到两个可以实时预览的markdown编辑器 一,sublime text 3 + MarkDown Editing + OmniMarkupPreviwer 安装方法网上均有,这里要 ...