POJ 1523 SPF(tarjan求割点)
2018-06-17 21:09:08来源:未知 阅读 ()
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9762 | Accepted: 4397 |
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
// luogu-judger-enable-o2 #include<cstdio> #include<cstring> #include<algorithm> //#define getchar() (S == T && (T = (S = BB) + fread(BB, 1, 1 << 15, stdin), S == T) ? EOF : *S++) //char BB[1 << 15], *S = BB, *T = BB; using namespace std; const int MAXN=1e5+10; inline int read() { char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } struct node { int u,v,nxt; }edge[MAXN]; int head[MAXN],num=1; inline void AddEdge(int x,int y) { edge[num].u=x; edge[num].v=y; edge[num].nxt=head[x]; head[x]=num++; } int low[MAXN],dfn[MAXN],ans[MAXN],tot=0,N; void tarjan(int now) { dfn[now]=low[now]=++tot; int ch=0; for(int i=head[now];i!=-1;i=edge[i].nxt) { if(!dfn[edge[i].v]) { tarjan(edge[i].v); low[now]=min(low[now],low[edge[i].v]); if(low[edge[i].v]>=dfn[now]) ans[now]++; } else low[now]=min(low[now],dfn[edge[i].v]); } } int main() { #ifdef WIN32 freopen("a.in","r",stdin); #else #endif int cur=0; while(1) { memset(head,-1,sizeof(head)); memset(ans,0,sizeof(ans)); memset(low,0,sizeof(low)); memset(dfn,0,sizeof(dfn)); num=1; bool flag=1; int x,y; while(1) { scanf("%d",&x); if(x==0) break; flag=0; scanf("%d",&y); AddEdge(x,y);AddEdge(y,x); N=max(N,max(x,y)); } if(flag==1) break; tarjan(1); flag=1; printf("Network #%d\n",++cur); if(ans[1]>1) printf(" SPF node %d leaves %d subnets\n",1,ans[1]),flag=0; for(int i=2;i<=N;i++) if(ans[i]>=1) printf(" SPF node %d leaves %d subnets\n",i,ans[i]+1),flag=0; if(flag==1) printf(" No SPF nodes\n"); putchar('\n'); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- POJ-3278 2020-04-01
- Asteroids!_poj2225 2020-02-09
- poj-1753题题解思路 2020-01-26
- POJ1852 2019-11-11
- POJ2431 优先队列+贪心 - biaobiao88 2019-11-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash