結果
| 問題 | No.583 鉄道同好会 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-21 01:43:55 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| 記録 | |
| コンパイル時間 | 886 ms |
| コンパイル使用メモリ | 99,740 KB |
| 実行使用メモリ | 1,483,008 KB |
| 最終ジャッジ日時 | 2026-02-21 01:43:59 |
| 合計ジャッジ時間 | 3,865 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 MLE * 1 |
| other | -- * 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", &t);
while (t--) {
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");
continue;
}
if (!Check()) {
puts("NO");
} else {
puts("YES");
}
}
return 0;
}