日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

poj 1523(无向联通图的割点)

發布時間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 1523(无向联通图的割点) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

結合tarjan算法思想,這題終于寫了出來。

同樣用dfs將圖變成為一顆樹,這樣可以提供許多有用的性質。

對于一個無向連通圖,dfs后的樹為只有回邊(回邊Euv,v是u的祖先)和生成樹的邊的圖。 那么在遍歷到一個點u的時候,可以知道如果不考慮這個點,如果與u相鄰的點連通那么u不是割點,否則是割點。 那么只需要判斷與u相鄰的點是否連通就行了,于是借鑒tarjan求強連通的辦法,在dfs時,對每個點標記一個深度low[N]也就是從根到這個點最短路徑(經過的最小結點數), 然后在遍歷到u點的時候,看看與u相鄰的點v的low[v], 如果low[U] >= low[u]那么說明u就是割點. ?因為v點無法到達u相鄰的某些點。 當然當u為根節點的時候要特判

?

SPF
Time Limit:?1000MS?Memory Limit:?10000K
Total Submissions:?4366?Accepted:?2009

Description

Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.?

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

The input will contain the description of several networks. A network description will consist of pairs of integers, one pair per line, that identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2 1 specify the same connection. All node numbers will range from 1 to 1000. A line containing a single zero ends the list of connected nodes. An empty network description flags the end of the input. Blank lines in the input file should be ignored.

Output

For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.?

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
01 2
2 3
3 4
4 5
5 1
01 2
2 3
3 4
4 6
6 3
2 5
5 1
00

Sample Output

Network #1SPF node 3 leaves 2 subnetsNetwork #2No SPF nodesNetwork #3SPF node 2 leaves 2 subnetsSPF node 3 leaves 2 subnets

Source

Greater New York 2000

?

// start time 12:44
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define N 1010
#define INF 0x3ffffff
int g[N][N];
int mark[N];
int low[N];
int save[N];
int n;void dfs(int s,int cnt)
{low[s]=cnt;int mi=INF;int k=0;for(int i=1;i<=n;i++){if(g[s][i]==0||s==i) continue;if(low[i] == -1){dfs(i,cnt+1);if( low[i] >= cnt ) k++;}mi=min(low[i],mi);}low[s]=mi;if(cnt==0) k--;if(k!=0) save[s]=k;
}int main()
{int tt=1;int x,y;while(scanf("%d",&x)&&x){memset(mark,0,sizeof(mark));mark[x]=1;n=0;if(x>n) n=x;memset(g,0,sizeof(g));memset(save,-1,sizeof(save));memset(low,-1,sizeof(low));scanf("%d",&y);mark[y]=1;if(y>n) n=y;g[x][y]=g[y][x]=1;while(scanf("%d",&x)&&x){mark[x]=1;if(x>n) n=x;scanf("%d",&y);mark[y]=1;if(y>n) n=y;g[x][y]=g[y][x]=1;}for(int i=1;i<=n;i++)if(mark[i]==1){dfs(i,0);break;}printf("Network #%d\n",tt++);int flag=0;for(int i=1;i<=n;i++){if(save[i]!=-1){flag=1;printf("  SPF node %d leaves %d subnets\n",i,save[i]+1);}}if(flag==0)printf("  No SPF nodes\n");printf("\n");}return 0;
}

?

轉載于:https://www.cnblogs.com/chenhuan001/archive/2013/05/13/3075662.html

總結

以上是生活随笔為你收集整理的poj 1523(无向联通图的割点)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。