UVA315 Network Connected Graph cutting Point

Source: Internet
Author: User

The main topic: the direction of the map to cut points

Topic Ideas:

A point u is a cut point when and only if one of the two two conditions is met:

1. The point is the root node and has at least two child nodes

2.u is not a root, and satisfies the presence (U,V) as a branch edge (or parent-child edge, that is, U is the father of V in the search tree), making DFN (U) <=low (v).

Then pay attention to the read in, Easy re

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<vector>#include<iostream>#include<algorithm>#defineMAXSIZE 1005#defineLL Long Longusing namespacestd;intVis[maxsize],map[maxsize][maxsize],low[maxsize],dfn[maxsize],pre[maxsize],time,n,ans,son;voidTarjan (intUintFA) {Pre[u]=A; Low[u]=dfn[u]=++Time ;  for(intI=1; i<=n; i++)    {        if(! Map[u][i] | | U==i)Continue; if(!Dfn[i])            {Tarjan (i,u); Low[u]=min (low[u],low[i]); }        Else if(fa!=i) {Low[u]=min (low[u],dfn[i]); }    }}voidInit () {memset (Map,0,sizeof(MAP)); memset (Low,0,sizeof(low)); memset (DFN,0,sizeof(DFN)); memset (Vis,0,sizeof(VIS)); memset (PRE,0,sizeof(pre)); time=0; Ans=0; Son=0;}intMain () {intb; CharCh,op;  while(SCANF ("%d",&N), N) {Init ();        GetChar ();  while(SCANF ("%d",&a), a) { while(SCANF ("%d%c",&b,&op)) {Map[a][b]=map[b][a]=1; if(op=='\ n') Break; }} Tarjan (1,0);  for(intI=2; i<=n;i++)        {            if(pre[i]==1) son++; Else if(Dfn[pre[i]] <=Low[i]) vis[pre[i]=1; }        if(Son >1) ans++;  for(intI=2; i<=n;i++)            if(Vis[i]) ans++; printf ("%d\n", ans); }    return 0;}
View Code

UVA315 Network Connected Graph 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.