Rogu P3388 [TEMPLATE] Cut Point (cut top) (tarjan seek cut point), p3388tarjan

Source: Internet
Author: User

Rogu P3388 [TEMPLATE] Cut Point (cut top) (tarjan seek cut point), p3388tarjan

Cut Point


Returns an undirected graph of n vertices and m edges, and calculates the cut point of the graph.

Input/Output Format

Input Format:


Input n, m in the first line

Input x in each row in the m line below, and y indicates that x to y has an edge.


Output Format:


Number of output cut points in the first line

The second line outputs the node numbers from small to large and is separated by spaces.


Input and Output sample input sample #1: Copy
6 71 21 31 42 53 54 55 6
Output example #1: Copy
1 5

N, m are 100000

The tarjan chart is not necessarily connected !!!



If $ low [v]> = dfn [u] $, it indicates that the point before $ u $ cannot be retrieved from $ v $.

Then, $ u $ can split $ v $ from the previous vertex.

The root node needs to be determined. Only when there are more than two children is the cut point.


// luogu-judger-enable-o2#include<cstdio>#include<cstring>#include<algorithm>#define getchar() (S == T && (T = (S = BB) + fread(BB, 1, 1 << 15, stdin), S == T) ? EOF : *S++)char BB[1 << 15], *S = BB, *T = BB;using namespace std;const int MAXN=1e6+10;inline int read(){    char c=getchar();int x=0,f=1;    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 u,v,nxt;}edge[MAXN];int head[MAXN],num=1;inline void AddEdge(int x,int y){    edge[num].u=x;    edge[num].v=y;    edge[num].nxt=head[x];    head[x]=num++;}int dfn[MAXN],low[MAXN],cut[MAXN],tot=0;int tarjan(int now,int fa){    int ch=0;    dfn[now]=low[now]=++tot;    for(int i=head[now];i!=-1;i=edge[i].nxt)    {        if(!dfn[edge[i].v])        {            tarjan(edge[i].v,fa);            low[now]=min(low[now],low[edge[i].v]);            if(low[edge[i].v]>=dfn[now]&&now!=fa) cut[now]=1;            if(now==fa) ch++;         }        low[now]=min(low[now],dfn[edge[i].v]);    }    if(now==fa&&ch>=2) cut[now]=1;}int main(){    #ifdef WIN32    freopen("","r",stdin);    #else    #endif    memset(head,-1,sizeof(head));    int N=read(),M=read();    for(int i=1;i<=M;i++)    {        int x=read(),y=read();        AddEdge(x,y);        AddEdge(y,x);    }    for(int i=1;i<=N;i++)        if(!dfn[i])            tarjan(i,i);    int ans=0;    for(int i=1;i<=N;i++)        if(cut[i]) ans++;    printf("%d\n",ans);    for(int i=1;i<=N;i++)        if(cut[i]) printf("%d ",i);    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.