Minimum Cut
传送门1
传送门2
Given a simple unweighted graph
We say that a cut in
Since love needs good faith and hypocrisy return for only grief, you should find the minimum cut of graph
Input
The input contains several test cases.
The first line of the input is a single integer
Then
Each test case contains several lines.
The first line contains two integers
The following
Next
Output
For each test case, you should output the minimum cut of graph
Sample Input
1
4 5
1 2
2 3
3 4
1 3
1 4
Sample Output
Case #1: 2
题意
给出一个图
分析
显然我们要把一个点从图中分离。那么这个点在树上的度一定为1,再取图上另外要删除的边最少的点,它的度就是另外要删除的边的条数,最后答案加1.
CODE
#include<cstdio>
#include<memory.h>
#define N 20005
int ct[N],dg[N];
int main() {
int T;
scanf("%d",&T);
for(int cas=1; cas<=T; cas++) {
int n,m;
scanf("%d%d",&n,&m);
memset(ct,0,sizeof ct);
memset(dg,0,sizeof dg);
int u,v;
for(int i=1; i<n; i++) {
scanf("%d%d",&u,&v);
dg[u]++;
dg[v]++;
}
for(int i=n; i<=m; i++) {
scanf("%d%d",&u,&v);
ct[u]++;
ct[v]++;
}
int res=2e9;
for(int i=2; i<=n; i++)if(dg[i]==1)if(res>ct[i])res=ct[i];
printf("Case #%d: %d\n",cas,res+1);
}
return 0;
}