删边【图】【并查集】

题目大意:
给出一个连通图,问最多能删掉几条边,使这个图依然联通。

I n p u t

4 6
1 2
1 3
1 4
2 3
2 4
3 4

O u t p u t

3

思路:
这道题。。。轻松水过。

方法一:并查集。

可以把有通路的点划为统一集合,然后求出正确答案。

方法二:搞事

我们知道,对于一个连通图,能割掉的边数=边数-点数+1,所以这道题。。。


代码:

#include <cstdio>
#include <iostream>
using namespace std;

int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    printf("%d\n",m-n+1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ssl_zyc/article/details/80970030
今日推荐