Graph theory algorithm (cutting point)

Source: Internet
Author: User

From one to the beginning of the question:

The so-called cut point, is a connected undirected graph, the deletion of a point and all the edges connected to it, the remaining points are no longer connected, then this point is the joint point.
Title: The number of points (N) of the given graph, the edge count (m), and the M-bar, the output of all the joint points of the graph, to the large loss.
n<=100000,m<=300000
Examples:
Input:
10 17
2 1
2 6
2 8
3 2
3 5
4 2
4 7
5 3
5 4
6 3
7 1
9 |
9}
9 {
8 2
9 6
10 8
Output:
3
2 6 8
The sample first behaves N and M, followed by M behavior M edge. Output first behavior cut the number of points, followed by small to large output cut point number.

When you see this problem, you want to remove any point, and then traverse it once to see if it is a connected graph, if not, it is a cut point.

But this complexity is O (n (n+m)) Critical timeout

Well, we have to delve into the characteristics of Dfs to find the cut point in linear time, i.e. O (n+m) time

First of all, we know there's going to be a cut in the loop, isn't it nonsense?

Then we want the root node to be the condition of the cut point, there must be a 2 sons node to be able to do it (*^▽^*)

Then, in search, how to judge a point is cut point

Theorem: In the graph G of undirected graphs, when and only if a point u exists a ergodic descendant node V cannot be connected back to a node older than u, this point u is a cut point

Proof: Consider any of the sub-nodes of U v. If V and the band can not find a more old node, then no matter what can not be connected back, in turn, if it exists, then must be able to continue to connect through the point of the back, you are not cut point.

The certificate is completed.

It is said that it is possible to connect from the current point back to a point that has been out of the stack, it is impossible, why: Because once the stack, then he can search the node has been searched. Because this is a no-map, then this point must not be connected to a stack of points up.

I'm done.

#include <cstdio>#include<cstring>#include<algorithm>#defineN 100000+10using namespacestd;intHead[n],num;structedge{intnext,to;}; Edge e[2*n* (n1)];voidAddint  from,intTo ) {e[++num].next=head[ from]; E[num].to=to ; head[ from]=num;}intFlag[n],dfn[n],low[n];inttim=0, tot;intRoot;voidDfsintUintFA) {    //vis[u]=1;tim++; Low[u]=dfn[u]=Tim; intson=0;  for(intI=head[u];i;i=E[i].next) {        intv=e[i].to; //if (V==FA) continue;        if(!Dfn[v]) {Son++;            DFS (V,U); Low[u]=min (low[u],low[v]); if(u!=root&&low[v]>=Dfn[u]) Flag[u]=1; if(u==root&&son>=2) Flag[u]=1; }        Else if(v!=FA) {Low[u]=min (low[u],dfn[v]); }    }    return;}intMain () {intn,m; scanf ("%d%d",&n,&m); intx, y;  for(intI=1; i<=m;i++) {scanf ("%d%d",&x,&y);        Add (x, y);    Add (y,x); } Root=1; DFS (1, Root); intCnt=0;  for(intI=1; i<=n;i++)    {        if(vis[i]==1) cnt++; //printf ("%d", I);} printf ("%d\n", CNT);  for(intI=1; i<=n;i++)    {        if(flag[i]==1) printf ("%d", i); }    return 0;}

Graph theory algorithm (cutting point)

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: info-contact@alibabacloud.com 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.