https://zhixincode.com/contest/16/problem/C?problem_id=239
题意:给定了无向连通简单图
G
G
G的点集,和图
G
G
G的边的一个子集
S
S
S,但没有给出边集
E
E
E。试判断
S
S
S有没有可能是图
G
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;
}
484

被折叠的 条评论
为什么被折叠?



