結果
| 問題 | No.583 鉄道同好会 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-21 16:45:35 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,091 bytes |
| 記録 | |
| コンパイル時間 | 741 ms |
| コンパイル使用メモリ | 93,172 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-02-21 16:45:38 |
| 合計ジャッジ時間 | 1,817 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;
const int N = 510;
int t, 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) { return fa[x] ? fa[x] = Find(fa[x]) : x; }
int main() {
// freopen("train.in", "r", stdin);
// freopen("train.out", "w", stdout);
scanf("%d%d", &n, &m);
memset(d, 0, sizeof(d));
memset(fa, 0, sizeof(fa));
p.clear();
s.clear();
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 (auto e : p) s.insert(Find(e));
if (s.size() >= 2) {
puts("NO");
return 0;
}
if (!Check()) {
puts("NO");
} else {
puts("YES");
}
return 0;
}