标签:tarjan算法 code tchar include name || names char turn
#include<cstdio>
#include<iostream>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long ll;
const int N = 20000 + 100,M = 100000+100;
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
struct node {
int v,nxt;
}e[M * 2];
int ejs,head[N],dfn[N],low[N],ans[N];
void add(int u,int v) {
e[++ejs].v = v;e[ejs].nxt = head[u]; head[u] = ejs;
}
int now;
int js;
int rd;
void tarjan(int u) {
int rd = 0;
low[u] = dfn[u] = ++js;
for(int i = head[u]; i; i = e[i].nxt) {
int v = e[i].v;
if(!dfn[v]) {
tarjan(v);
if(u == now)
rd++;
low[u] = min(low[u],low[v]);
if(low[v] >= dfn[u] && u != now) ans[u] = 1;//!!!
}
else low[u] = min(low[u],dfn[v]);
}
if(rd >= 2 && u == now ) ans[u] = 1;
return;
}
int main() {
int n = read(), m = read();
for(int i = 1;i <= m;++i) {
int u = read(), v = read();
add(u,v); add(v,u);
}
for(int i = 1;i <= n;++i) {
if(!dfn[i]) {
now = i;
tarjan(i);
}
}
int tot = 0;
for(int i =1; i <= n;++i)
if(ans[i]) tot++;
printf("%d\n",tot);
for(int i = 1; i <= n;++i)
if(ans[i]) printf("%d ",i);
return 0;
}
标签:tarjan算法 code tchar include name || names char turn
原文地址:https://www.cnblogs.com/wxyww/p/9813406.html