結果

問題 No.100 直列あみだくじ
ユーザー rlangevinrlangevin
提出日時 2023-07-14 12:29:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,076 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 71,440 KB
最終ジャッジ日時 2023-10-14 01:57:06
合計ジャッジ時間 6,520 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,772 KB
testcase_01 AC 73 ms
71,048 KB
testcase_02 AC 73 ms
71,152 KB
testcase_03 AC 74 ms
70,940 KB
testcase_04 AC 74 ms
70,936 KB
testcase_05 AC 74 ms
70,920 KB
testcase_06 AC 72 ms
70,976 KB
testcase_07 AC 74 ms
71,024 KB
testcase_08 AC 73 ms
70,968 KB
testcase_09 AC 73 ms
71,016 KB
testcase_10 AC 74 ms
71,068 KB
testcase_11 AC 73 ms
71,004 KB
testcase_12 AC 74 ms
71,248 KB
testcase_13 AC 73 ms
70,920 KB
testcase_14 WA -
testcase_15 AC 73 ms
71,320 KB
testcase_16 AC 74 ms
71,232 KB
testcase_17 AC 74 ms
70,960 KB
testcase_18 AC 73 ms
70,976 KB
testcase_19 AC 72 ms
70,940 KB
testcase_20 AC 75 ms
71,208 KB
testcase_21 WA -
testcase_22 AC 73 ms
71,016 KB
testcase_23 AC 72 ms
70,960 KB
testcase_24 AC 71 ms
71,276 KB
testcase_25 AC 73 ms
71,212 KB
testcase_26 AC 72 ms
70,960 KB
testcase_27 AC 71 ms
70,996 KB
testcase_28 AC 73 ms
71,092 KB
testcase_29 AC 73 ms
70,940 KB
testcase_30 AC 73 ms
70,776 KB
testcase_31 AC 71 ms
71,108 KB
testcase_32 AC 71 ms
71,088 KB
testcase_33 WA -
testcase_34 AC 72 ms
70,928 KB
testcase_35 AC 73 ms
71,012 KB
testcase_36 AC 73 ms
70,968 KB
testcase_37 AC 70 ms
71,136 KB
testcase_38 WA -
testcase_39 AC 72 ms
70,768 KB
testcase_40 WA -
testcase_41 AC 72 ms
70,928 KB
testcase_42 AC 70 ms
70,852 KB
testcase_43 WA -
testcase_44 AC 73 ms
71,068 KB
testcase_45 AC 73 ms
71,156 KB
testcase_46 AC 73 ms
71,160 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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)

for i in range(N):
    if (U.get_size(i) - 1) % 2:
        print("No")
        exit()
print("Yes")
0