結果

問題 No.100 直列あみだくじ
ユーザー rlangevinrlangevin
提出日時 2023-11-29 00:53:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 1,255 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 55,624 KB
最終ジャッジ日時 2023-11-29 00:53:46
合計ジャッジ時間 4,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,620 KB
testcase_01 AC 45 ms
55,620 KB
testcase_02 AC 45 ms
55,620 KB
testcase_03 AC 44 ms
55,620 KB
testcase_04 AC 45 ms
55,620 KB
testcase_05 AC 40 ms
55,624 KB
testcase_06 AC 40 ms
55,624 KB
testcase_07 AC 45 ms
55,624 KB
testcase_08 AC 40 ms
55,624 KB
testcase_09 AC 40 ms
55,624 KB
testcase_10 AC 40 ms
55,624 KB
testcase_11 AC 40 ms
55,624 KB
testcase_12 AC 40 ms
55,624 KB
testcase_13 AC 40 ms
55,624 KB
testcase_14 AC 40 ms
55,624 KB
testcase_15 AC 39 ms
55,624 KB
testcase_16 AC 39 ms
55,624 KB
testcase_17 AC 39 ms
55,624 KB
testcase_18 AC 39 ms
55,624 KB
testcase_19 AC 40 ms
55,624 KB
testcase_20 AC 39 ms
55,624 KB
testcase_21 AC 40 ms
55,624 KB
testcase_22 AC 40 ms
55,624 KB
testcase_23 AC 40 ms
55,624 KB
testcase_24 AC 41 ms
55,624 KB
testcase_25 AC 40 ms
55,624 KB
testcase_26 AC 39 ms
55,624 KB
testcase_27 AC 39 ms
55,624 KB
testcase_28 AC 45 ms
55,624 KB
testcase_29 AC 39 ms
55,624 KB
testcase_30 AC 39 ms
55,620 KB
testcase_31 AC 45 ms
55,624 KB
testcase_32 AC 39 ms
55,620 KB
testcase_33 AC 40 ms
55,624 KB
testcase_34 AC 39 ms
55,624 KB
testcase_35 AC 39 ms
55,620 KB
testcase_36 AC 40 ms
55,620 KB
testcase_37 AC 40 ms
55,620 KB
testcase_38 AC 39 ms
55,620 KB
testcase_39 AC 40 ms
55,620 KB
testcase_40 AC 39 ms
55,620 KB
testcase_41 AC 39 ms
55,620 KB
testcase_42 AC 40 ms
55,620 KB
testcase_43 AC 39 ms
55,620 KB
testcase_44 AC 40 ms
55,620 KB
testcase_45 AC 39 ms
55,620 KB
testcase_46 AC 40 ms
55,620 KB
testcase_47 AC 39 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

N = int(input())
A = list(map(int, input().split()))
U = UnionFind(N)
for i in range(N):
    U.union(i, A[i] - 1)
    
from collections import *
S = set()
D = defaultdict(int)
for i in range(N):
    ui = U.find(i)
    if ui in S:
        continue
    if U.get_size(i) % 2 == 0:
        D[U.get_size(i)] += 1
    S.add(ui)
       
for k, v in D.items():
    if v % 2:
        print("No")
        exit()
        
print("Yes")
0