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