Description
Node 3 is therefore a Single Point of Failure (SPF) for this network. Strictly, an SPF will be defined as any node that, if unavailable, would prevent at least one pair of available nodes from being able to communicate on what was previously a fully connected network. Note that the network on the right has no such node; there is no SPF in the network. At least two machines must fail before there are any pairs of available nodes which cannot communicate.
Input
Output
The first network in the file should be identified as "Network #1", the second as "Network #2", etc. For each SPF node, output a line, formatted as shown in the examples below, that identifies the node and the number of fully connected subnets that remain when that node fails. If the network has no SPF nodes, simply output the text "No SPF nodes" instead of a list of SPF nodes.
Sample Input
1 2
5 4
3 1
3 2
3 4
3 5
0 1 2
2 3
3 4
4 5
5 1
0 1 2
2 3
3 4
4 6
6 3
2 5
5 1
0 0
Sample Output
Network #1
SPF node 3 leaves 2 subnets Network #2
No SPF nodes Network #3
SPF node 2 leaves 2 subnets
SPF node 3 leaves 2 subnets
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int dfn[];
int low[];
int head[];
int ans[];
int visit[];
int index,root,son,node,jiedge;
struct is
{
int u,v;
int next;
}edge[];
void add(int x,int y)
{
jiedge++;
edge[jiedge].u=x;
edge[jiedge].v=y;
edge[jiedge].next=head[x];
head[x]=jiedge;
jiedge++;
edge[jiedge].u=y;
edge[jiedge].v=x;
edge[jiedge].next=head[y];
head[y]=jiedge;
}
void dfs(int u)
{
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].v;
if(visit[v]==)
{
visit[v]=;++index;
dfn[v]=low[v]=index;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u==root)
son++;
else
ans[u]++;
}
}
else
low[u]=min(low[u],dfn[v]);
}
}
void trajan()
{
memset(visit,,sizeof(visit));
memset(ans,,sizeof(ans));
index=;
root=;
son=;
low[]=dfn[]=;
visit[]=;
dfs();
}
int main()
{
int u,v;
int flag=;
while(scanf("%d",&u)!=EOF)
{
memset(head,,sizeof(head));
jiedge=;
node=;
if(u==)
break;
scanf("%d",&v);
node=max(node,u);
node=max(node,v);
add(u,v);
while()
{
scanf("%d",&u);
if(u==)
break;
scanf("%d",&v);
add(u,v);
node=max(node,u);
node=max(node,v);
}
trajan();
int kk=;
if(flag!=)
printf("\n");
printf("Network #%d\n",++flag);
if(son>)
{
kk=;
printf(" SPF node %d leaves %d subnets\n",,son);
}
for(int i=;i<=node;i++)
{
if(ans[i])
{
kk=;
printf(" SPF node %d leaves %d subnets\n",i,ans[i]+);
}
}
if(kk)
printf(" No SPF nodes\n");
}
return ;
}