Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7110 | Accepted: 3242 |
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
Source
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
//#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************************************
struct ss
{
int to,next;
}e[];
int dfn[],n,flag,low[],head[],cnt,t,iscut[];
void add(int u,int v)
{
e[t].to=v;
e[t].next=head[u];
head[u]=t++;
}
void init(){
cnt=;
t=;
flag=;
n=;
memset(head,,sizeof(head));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
}
void tarjan(int x)
{
dfn[x]=low[x]=++cnt;
for(int i=head[x];i;i=e[i].next)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[x]=min(low[x],low[e[i].to]);
if(dfn[x]<=low[e[i].to])iscut[x]++;
}
else low[x]=min(low[x],dfn[e[i].to]);
}
}
int main()
{
int a,b;
int oo=;
while(scanf("%d",&a)!=EOF)
{
if(a==)break;
init();
scanf("%d",&b);
n=max(max(a,b),n);
add(a,b);
add(b,a);
while(scanf("%d",&a)&&a)
{
scanf("%d",&b);
n=max(max(a,b),n);
add(a,b);
add(b,a);
}
for(int i=;i<=n;i++)
{
iscut[i]=;
}
iscut[]=;///1为根必认定为割点
tarjan();
printf("Network #%d\n",oo++);
for(int i=;i<=n;i++)
{
if(iscut[i]>=){
flag=;
printf(" SPF node %d leaves %d subnets\n",i,iscut[i]);
}
}
if(!flag){
printf(" No SPF nodes\n");
}
printf("\n");
}
return ;
}