結果

問題 No.482 あなたの名は
ユーザー brthyyjpbrthyyjp
提出日時 2020-10-05 05:14:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 111,932 KB
最終ジャッジ日時 2023-09-27 01:34:14
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,332 KB
testcase_01 AC 76 ms
71,316 KB
testcase_02 AC 76 ms
71,592 KB
testcase_03 AC 76 ms
71,432 KB
testcase_04 AC 77 ms
71,404 KB
testcase_05 AC 76 ms
71,400 KB
testcase_06 AC 74 ms
71,244 KB
testcase_07 AC 79 ms
75,104 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 76 ms
71,324 KB
testcase_11 AC 80 ms
75,180 KB
testcase_12 AC 79 ms
75,228 KB
testcase_13 AC 79 ms
71,432 KB
testcase_14 AC 76 ms
71,440 KB
testcase_15 AC 178 ms
111,740 KB
testcase_16 AC 176 ms
111,688 KB
testcase_17 AC 178 ms
111,656 KB
testcase_18 AC 175 ms
111,544 KB
testcase_19 AC 179 ms
111,548 KB
testcase_20 AC 176 ms
111,932 KB
testcase_21 AC 181 ms
111,640 KB
testcase_22 AC 184 ms
111,596 KB
testcase_23 AC 177 ms
111,464 KB
testcase_24 AC 180 ms
111,712 KB
testcase_25 AC 174 ms
111,524 KB
testcase_26 AC 176 ms
111,804 KB
testcase_27 AC 179 ms
111,604 KB
testcase_28 AC 177 ms
111,568 KB
testcase_29 AC 136 ms
111,588 KB
testcase_30 AC 75 ms
71,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
D = list(map(int, input().split()))

D = [d-1 for d in D]

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

par = [-1]* n
rank = [0]*n

for i, d in enumerate(D):
    Unite(i, d, par, rank)
c = 0
for i in range(n):
    if par[i] < 0:
        c += -par[i]-1
if (k-c)%2 == 0:
    print('YES')
else:
    print('NO')
0