Wannafly Winter Camp 2019 Day4 C 最小边覆盖 (水题)

版权声明:欢迎神犇指教 https://blog.csdn.net/sdxtcqs/article/details/86625787

https://zhixincode.com/contest/16/problem/C?problem_id=239
题意:给定了无向连通简单图 G G 的点集,和图 G G 的边的一个子集 S S ,但没有给出边集 E E 。试判断 S S 有没有可能是图 G G 的最小边覆盖。

这题给了点乱七八糟的结论,然而并没什么卵用,这个题只需要判断就行,所以统计一下每个点的度数,然后每个点都是出度为1且入度为1才是Yes。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int a[300010],b[300010];
int h[200010];
bool res=1;

int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        h[a[i]]++;
        h[b[i]]++;
    }
    for(int i=1;i<=m;i++)
        if(h[a[i]]>=2 && h[b[i]]>=2)
            res=0;
    for(int i=1;i<=n;i++)
        if (!h[i])
            res = false;
    if(res)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sdxtcqs/article/details/86625787
今日推荐