結果
| 問題 | No.583 鉄道同好会 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-21 01:51:43 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 1,176 bytes |
| 記録 | |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 100,640 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-02-21 01:51:45 |
| 合計ジャッジ時間 | 1,591 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;
const int N = 510;
int n, m, d[N], fa[N];
set<int> p, s;
bool Check() {
int cnt = 0;
for (auto e : p) {
if (d[e] % 2 != 0) {
++cnt;
}
}
if (cnt == 0 || cnt == 2) return true;
else return false;
}
int Find(int x) {
if (fa[x] != x) fa[x] = Find(fa[x]);
return fa[x];
}
int main() {
// freopen("train.in", "r", stdin);
// freopen("train.out", "w", stdout);
scanf("%d%d", &n, &m);
memset(d, 0, sizeof(d));
p.clear();
s.clear();
for (int i = 1; i <= n; ++i) fa[i] = i;
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d%d", &u, &v);
int fx = Find(u), fy = Find(v);
if (fx != fy) {
fa[fx] = fy;
}
++d[u], ++d[v];
p.insert(u);
p.insert(v);
}
for (int i = 1; i <= n; ++i) fa[i] = Find(i);
for (auto e : p) s.insert(Find(e));
if (s.size() >= 2) {
puts("NO");
return 0;
}
if (!Check()) {
puts("NO");
} else {
puts("YES");
}
return 0;
}