The most basic problem of cutting points, suggest in-depth understanding of the DFS process, and for the same point, to meet it is the condition of the cut point may be set up several times, so be sure to count the number of cut points after the end of the DFS, rather than in the DFS process implemented.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 6 Const intN = $;7 Const intM = -;8 intDfn[n];9 intLow[n];Ten intHead[n]; One BOOLIs_cut[n]; A intN, E, dfs_clock; - - voidInit () the { -E = Dfs_clock =0; -Memset (Head,-1,sizeof(head)); -memset (DFN,0,sizeof(DFN)); +memset (Is_cut,0,sizeof(Is_cut)); - } + A structEdge at { - intV, next; - } Edge[m]; - - voidAddedge (intUintv) - { inEDGE[E].V =v; -Edge[e].next =Head[u]; toHead[u] = e++; + } - the voidDfsintUintFA) * { $Low[u] = Dfn[u] = + +Dfs_clock;Panax Notoginseng intCNT =0; - for(inti = Head[u]; I! =-1; i =edge[i].next) the { + intv =edge[i].v; A if( !Dfn[v]) the { +cnt++; - Dfs (v, u); $ if(Low[v] >= dfn[u]) is_cut[u] =true; $Low[u] =min (Low[u], low[v]); - } - Else if(V! =FA) the { -Low[u] =min (Low[u], dfn[v]);Wuyi } the } - if(FA <0&& CNT = =1) Is_cut[u] =false; Wu } - About intMain () $ { - while(SCANF ("%d", &N), N) - { - init (); A intu, v; + while(SCANF ("%d", &u), u) the { - while(GetChar ()! ='\ n' ) $ { thescanf"%d", &v); the Addedge (U, v); the Addedge (V, u); the } - } inDfs1, -1 ); the intAns =0; the for(inti =1; I <= N; i++ ) About { the if(Is_cut[i]) ans++; the } theprintf"%d\n", ans); + } - return 0; the}
POJ 1144 Cut Point