水题。无向图欧拉通路的判定。用并查集判定是不是连通图!
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = + ;
int tott[maxn];
int father[maxn]; int find(int x)
{
if (x != father[x]) father[x] = find(father[x]);
return father[x];
} int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int i, n, m, u, v;
scanf("%d%d", &n, &m);
for (i = ; i <= n; i++) father[i] = i;
memset(tott, , sizeof(tott));
for (i = ; i < m; i++)
{
scanf("%d%d", &u, &v);
int fu = find(u);
int fv = find(v);
if (fu != fv) father[fu] = fv;
tott[u]++;
tott[v]++;
}
int ji = , ou = ;
for (i = ; i <= n; i++)
{
if (tott[i] == ) continue;
if (tott[i] % == ) ou++;
else ji++;
}
int jieguo = ;
int th = find();
for (i = ; i <= n; i++)
{
int tg = find(i);
if (tg != th) break;
}
if (i == n + ) jieguo = ;
if (jieguo == )
{
if (ji == || ji == ) jieguo = ;
else jieguo = ;
}
if (jieguo == ) printf("Yes\n");
else printf("No\n");
}
return ;
}