poj1523 割顶

简介:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int cut[1011], pre[1011];
vector<int> g[1011];
int ans, dfs_clock, son;
int dfs(int u, int fa){
	int lowu = pre[u] = ++dfs_clock;
	int child = 0;
	for (int i = 0; i < g[u].size(); i++){
		int v = g[u][i];
		if (!pre[v]){
			child ++;
			int lowv = dfs(v, u);
			if (pre[u] <= lowv){
				cut[u] ++;
			}
		
			lowu = min(lowu, lowv);
		}
		else if (pre[u] > pre[v]) lowu = min(lowu, pre[v]);
	}
	if (fa < 0)
		cut[u] = child - 1;
	return lowu;
}
int main(){
	int t = 0, u, v, n = -1;
	while (cin>>u && u){
		dfs_clock = ans = 0;
		for (int i = 1; i <=1000; i++) g[i].clear();
		memset(cut, 0, sizeof(cut));
		memset(pre, 0, sizeof(pre));
		while (u){
			cin>>v;
			n = max(n, max(u, v));
			g[u].push_back(v); g[v].push_back(u);
			cin>>u;
		}
		for (int i = 1; i <= n; i++)
		    if (!pre[i]) dfs(i, -1);
		printf("Network #%d\n", ++t);
		bool flag = 0;
		for (int i = 1; i <= n; i++)
		    if (cut[i] > 0) {
			    printf("  SPF node %d leaves %d subnets\n", i, cut[i] + 1);
			    flag = 1;}
        if (!flag) printf("  No SPF nodes\n");
        printf("\n");
	}
}

相关文章
poj 1455
Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.
618 0
|
并行计算 网络架构
poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned ...
986 0
poj题目分类
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html
770 0
|
人工智能 vr&ar
|
算法 计算机视觉
最小割-poj-2914
poj-2914-Minimum Cut Description Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must b
1561 0