結果
| 問題 | No.583 鉄道同好会 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-21 01:45:01 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,078 bytes |
| 記録 | |
| コンパイル時間 | 809 ms |
| コンパイル使用メモリ | 99,868 KB |
| 実行使用メモリ | 1,484,672 KB |
| 最終ジャッジ日時 | 2026-02-21 01:45:06 |
| 合計ジャッジ時間 | 3,661 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 2 MLE * 1 -- * 8 |
ソースコード
#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) { 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);
fa[u] = v;
++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(fa[e]);
if (s.size() >= 2) {
puts("NO");
return 0;
}
if (!Check()) {
puts("NO");
} else {
puts("YES");
}
return 0;
}