結果
問題 | No.100 直列あみだくじ |
ユーザー |
![]() |
提出日時 | 2020-05-14 11:28:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,034 bytes |
コンパイル時間 | 1,585 ms |
コンパイル使用メモリ | 170,592 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-15 01:55:37 |
合計ジャッジ時間 | 3,293 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 WA * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> data; UnionFind(int n) { data.assign(n, -1); } bool unite(int x, int y) { x = root(x), y = root(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int root(int k) { if (data[k] < 0) return (k); return (data[k] = root(data[k])); } bool same(int x, int y) { return root(x) == root(y); } int size(int k) { return (-data[root(k)]); } }; int main() { int N, a[60] = {}; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; a[i]--; } UnionFind uf(N); for (int i = 0; i < N; i++) { uf.unite(i, a[i]); } for (int i = 0; i < N; i++) { if (uf.size(i) % 2 == 0) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }