You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
// 扩展知识:欧拉通路,欧拉回路
// https://www.cnblogs.com/graytido/p/10421927.html
// 并查集+欧拉回路
typedef long long LL;
const LL N = 1e3 + 7;
const LL MOD = 1e9 + 7;
int pre[N];
int n, m;
int degree[N];
int find(int x) //查找根结点
{
int r = x;
while (r != pre[r]) //寻找根结点
r = pre[r];
int i = x, j;
while (pre[i] != r) //路径压缩
{
j = pre[i];
pre[i] = r;
i = j;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
while (cin >> n && n) {
cin >> m;
memset(degree, 0, sizeof(degree));
for (int i = 1; i <= n; i++)
pre[i] = i;
while (m--) {
int a, b;
cin >> a >> b;
int fa = find(a);
int fb = find(b);
if (fa != fb) {
pre[a] = b;
degree[a]++;
degree[b]++;
}
}
int flag = 1;
for (int i = 2; i <= n; i++) {
if (degree[i] & 1 || pre[i] != pre[1]) {
flag = 0;
break;
}
}
cout << flag << endl;
}
return 0;
}