1 /*****************************************2 SPF (POJ 1523)3 Getting started with cutting points4 http://poj.org/problem?id=15235 6 ******************************************/7 8#include <iostream>9#include <algorithm>Ten#include <cstdio> One#include <cstring> A#include <vector> - using namespacestd; - the Const intm=1005; -vector<int>G[m]; - intDfn[m],low[m]; - intVs[m],num[m]; + intDfs_cut; - + voidInit () A { at for(intI=0; i<m;i++) g[i].clear (); -memset (DFN,0,sizeof(DFN)); -memset (Low,0,sizeof(Low)); -Memset (VS,0,sizeof(VS)); -memset (NUM,0,sizeof(num)); -dfs_cut=0; in } - to voidDfsintu) + { -vs[u]=1; thelow[u]=dfn[u]=++Dfs_cut; * for(intI=0; I<g[u].size (); i++) $ {Panax Notoginseng intv=G[u][i]; - if(!Vs[v]) the { + Dfs (v); Alow[u]=min (low[u],low[v]); the if(Low[v]>=dfn[u]) num[u]++; + } - Elselow[u]=min (low[u],dfn[v]); $ } $ } - - intMain () the { - intu,v,k=1;Wuyi while(cin>>u&&u) the { - Init (); WuCin>>v; - G[u].push_back (v); About g[v].push_back (u); $ while(cin>>u&&u) - { -Cin>>v; - G[u].push_back (v); A g[v].push_back (u); + } theDfs1); - if(num[1]) num[1]--;///Num records the number of children, but 1 doesn't have a father, so let it-1, last output the same plus 1 $ ///feel num[i]>0 is certain, but do not judge will be wrong, perhaps there are 1 1 this set of data bar. theprintf"Network #%d\n", k++); the intflag=1; the for(intI=1; i<m;i++) the { - if(Num[i]) in { theprintf"SPF node%d leaves%d subnets\n", i,num[i]+1); theflag=0; About } the } the if(flag) printf ("No SPF nodes\n"); theprintf"\ n"); + } -}
SPF (POJ 1523) Getting started with cutting points