結果
問題 |
No.482 あなたの名は
|
ユーザー |
|
提出日時 | 2020-04-06 16:23:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 655 bytes |
コンパイル時間 | 88 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 33,560 KB |
最終ジャッジ日時 | 2024-07-06 12:27:21 |
合計ジャッジ時間 | 5,617 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 28 |
ソースコード
class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] def find(self, x): if self.parent[x] == x: return x self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return self.parent[x] = y N, K = map(int, input().split()) D = list(map(int, input().split())) uf = UnionFind(N + 1) for i in range(N): uf.union(i + 1, D[i]) s = set(uf.find(i) for i in range(1, N + 1)) cnt = N - len(s) yes = ans <= K and ans % 2 == K % 2 print('YES' if yes else 'NO')