看了半天都没看懂。。。最后查了题解才知道是什么意思。。。。
题意: 给你一个无权无向图,图里面有个树,问你在删这个树的一个边后,还要删多少条边才能使这个图不连通(包括删树边)
妈耶。。。。。这是个水题啊啊啊啊啊啊啊啊啊啊啊!!!!!
思路: 首先删树边肯定要删度数为1的边,但是怎么删呢。。。这个就可以不用管,我们只要找到这个树的所有节点(度数为一),然后找这些节点中最小的就好了
#include<cstdio>
#include <iostream>
#include<string>
#include<cstring>
using namespace std;
int tt[100000] , gt[1000000] ;
int main ()
{
int t ;
cin >> t ;
int k = 1 ;
while(t--){
memset(gt , 0 , sizeof(gt)) ;
memset(tt , 0 , sizeof(tt)) ;
int n , m ;
scanf("%d %d",&n,&m) ;
int x , y ;
for(int i = 0 ; i < n - 1 ; i++){
scanf("%d %d",&x,&y) ;
tt[x]++ ;
tt[y]++ ;
}
for(int i = 0 ; i < m - n + 1 ; i++){
scanf("%d %d",&x,&y) ;
gt[x]++ ; gt[y] ++ ;
}
int ans = 1e9 + 10 ;
for(int i = 1 ; i <= n ; i++){
if(tt[i] == 1 && ans > gt[i] ) ans = gt[i] ;
}
printf("Case #%d: %d\n",k++,ans + 1 ) ;
}
}