HDU 5452 Minimum Cut(贪心)

思路:只能切一条生成树上的边,一个比较直观的想法是只切度数为1的点的那条边,然后枚举这个叶子和外面连接的边数即可


#include<bits/stdc++.h>
using namespace std;
const int maxn = 20000+7;
#define inf 1e9
vector<int>e[maxn];
int vis[maxn];
int deg[maxn],degg[maxn];
int n,m;
int main()
{
	int T,cas=1;
	scanf("%d",&T);
	while(T--)
	{
		memset(deg,0,sizeof(deg));
		memset(degg,0,sizeof(degg));
		memset(vis,0,sizeof(vis));
        printf("Case #%d: ",cas++);
        scanf("%d%d",&n,&m);
		for(int i = 0;i<n-1;i++)
		{
            int u,v;
			scanf("%d%d",&u,&v);
			deg[u]++;
			deg[v]++;
			if(deg[u]>1)
				vis[u]=1;
			if(deg[v]>1)
				vis[v]=1;
		}
		for(int i = 0;i<m-n+1;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			degg[u]++;
			degg[v]++;
		}
		int ans = inf;
		for(int i = 1;i<=n;i++)
			if(!vis[i])
				ans = min(ans,deg[i]+degg[i]);
		printf("%d\n",ans);
	}
}


Description

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

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

Input

The input contains several test cases. 
The first line of the input is a single integer   which is the number of test cases. 
Then   test cases follow. 

Each test case contains several lines. 
The first line contains two integers   and 
The following   lines describe the spanning tree   and each of them contains two integers   and   corresponding to an edge. 
Next   lines describe the undirected graph   and each of them contains two integers   and   corresponding to an edge which is not in the spanning tree  .

Output

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

Sample Input

1
4 5
1 2
2 3
3 4
1 3
1 4

Sample Output

Case #1: 2


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值