結果

問題 No.482 あなたの名は
ユーザー yomo3yomo3
提出日時 2020-04-06 16:24:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 30,956 KB
最終ジャッジ日時 2023-09-20 17:30:23
合計ジャッジ時間 6,489 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 17 ms
7,984 KB
testcase_03 AC 16 ms
7,812 KB
testcase_04 AC 15 ms
7,824 KB
testcase_05 AC 16 ms
7,804 KB
testcase_06 AC 16 ms
7,856 KB
testcase_07 AC 17 ms
8,288 KB
testcase_08 AC 16 ms
8,308 KB
testcase_09 AC 16 ms
7,788 KB
testcase_10 AC 16 ms
8,256 KB
testcase_11 AC 16 ms
8,428 KB
testcase_12 AC 17 ms
8,300 KB
testcase_13 AC 16 ms
8,256 KB
testcase_14 AC 16 ms
8,188 KB
testcase_15 AC 259 ms
30,936 KB
testcase_16 AC 263 ms
30,692 KB
testcase_17 AC 258 ms
30,956 KB
testcase_18 AC 266 ms
30,724 KB
testcase_19 AC 261 ms
30,832 KB
testcase_20 AC 258 ms
30,904 KB
testcase_21 AC 258 ms
30,888 KB
testcase_22 AC 259 ms
30,656 KB
testcase_23 AC 258 ms
30,936 KB
testcase_24 AC 259 ms
30,728 KB
testcase_25 AC 258 ms
30,888 KB
testcase_26 AC 265 ms
30,912 KB
testcase_27 AC 260 ms
30,688 KB
testcase_28 AC 260 ms
30,848 KB
testcase_29 AC 213 ms
30,660 KB
testcase_30 AC 16 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = cnt <= K and cnt % 2 == K % 2
print('YES' if yes else 'NO')
0