Hdu 5452 Minimum Cut (图论问题) 2015 ACM-ICPC沈阳网赛


 Hdu 5452 Minimum Cut (图论问题) 2015 ACM-ICPC沈阳网赛

 

Minimum Cut

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 1314    Accepted Submission(s): 608


Problem Description
Given a simple unweighted graph  G  (an undirected graph containing no loops nor multiple edges) with  n  nodes and  m  edges. Let  T  be a spanning tree of  G .
We say that a cut in  G  respects  T  if it cuts just one edges of  T .

Since love needs good faith and hypocrisy return for only grief, you should find the minimum cut of graph  G  respecting the given spanning tree  T .
 

Input
The input contains several test cases.
The first line of the input is a single integer  t (1t5)  which is the number of test cases.
Then  t  test cases follow.

Each test case contains several lines.
The first line contains two integers  n (2n20000)  and  m (n1m200000) .
The following  n1  lines describe the spanning tree  T  and each of them contains two integers  u  and  v  corresponding to an edge.
Next  mn+1  lines describe the undirected graph  G  and each of them contains two integers  u  and  v  corresponding to an edge which is not in the spanning tree  T .
 

Output
For each test case, you should output the minimum cut of graph  G  respecting the given spanning tree  T .
 

Sample Input
  
  
1 4 5 1 2 2 3 3 4 1 3 1 4
 

Sample Output
  
  
Case #1: 2
 

Source
 
题意:给一个无权有向图G,图上给一颗生成树T,去掉最少的边(必须有一条边在树上)使图不再连通。
分析:生成树T性质,包含图上所有的结点,n即结点数。而选择生成树的叶子结点的边切割不会比非叶子结点更差,因为叶子结点没有子树,所以算法十分明显,
       枚举所有的叶子结点的非生成树边的入度(等于总度数),找到最小的再加一即是答案(必须有一条边在树上)。

 

/*	
	题意:给一个无权有向图G,图上给一颗生成树T,去掉最少的边(必须有一条边在树上)使图不再连通。
	分析:生成树T性质,包含图上所有的结点,n即结点数。而选择生成树的叶子结点的边切割不会比非叶子结点更差,因为叶子结点没有子树,所以算法十分明显,
枚举所有的叶子结点的非生成树边的入度(等于总度数),找到最小的再加一即是答案(必须有一条边在树上)。
*/
#include<iostream>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 1<<29
#define eps 1e-9
#define LD long double
#define LL long long
const int maxn = 200000 + 10;
using namespace std;
int rdegree[maxn], vdegree[maxn];
int main()
{
#ifdef LOCAL
	freopen("data.txt", "r", stdin);
#endif
	int T;
	scanf("%d",&T);
	for (int kase = 1; kase <= T; ++kase)
	{
		memset(rdegree, 0, sizeof(rdegree));
		memset(vdegree, 0, sizeof(vdegree));
		int n, m,u, v;
		scanf("%d%d", &n,&m);
		for (int i = 1; i < n; i++)
		{
			
			scanf("%d%d", &u, &v);
			rdegree[u]++;
			rdegree[v]++;
		}
		for (int i = n; i <= m; i++){
			scanf("%d%d", &u, &v);
			vdegree[u]++;
			vdegree[v]++;
		}
		int MinCut = 1 << 30;
		for (int i = 1; i <= n; i++){
			if (rdegree[i]<2){
				MinCut = min(MinCut, vdegree[i]);
			}
		}
		printf("Case #%d: %d\n", kase, MinCut + 1);
	}	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值