結果

問題 No.2780 The Bottle Imp
ユーザー anan
提出日時 2024-06-07 23:09:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,558 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 81,100 KB
最終ジャッジ日時 2024-06-08 10:37:44
合計ジャッジ時間 7,353 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,252 KB
testcase_01 AC 46 ms
54,684 KB
testcase_02 AC 46 ms
54,392 KB
testcase_03 AC 44 ms
55,076 KB
testcase_04 AC 43 ms
55,116 KB
testcase_05 AC 43 ms
54,736 KB
testcase_06 AC 42 ms
55,556 KB
testcase_07 AC 201 ms
78,128 KB
testcase_08 AC 264 ms
79,040 KB
testcase_09 AC 209 ms
78,372 KB
testcase_10 AC 228 ms
78,344 KB
testcase_11 AC 205 ms
78,272 KB
testcase_12 AC 332 ms
79,596 KB
testcase_13 AC 294 ms
78,864 KB
testcase_14 AC 111 ms
77,352 KB
testcase_15 AC 123 ms
77,352 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 115 ms
77,412 KB
testcase_19 AC 111 ms
77,220 KB
testcase_20 AC 110 ms
77,132 KB
testcase_21 WA -
testcase_22 AC 165 ms
78,092 KB
testcase_23 AC 144 ms
77,664 KB
testcase_24 AC 183 ms
77,684 KB
testcase_25 AC 289 ms
78,896 KB
testcase_26 AC 200 ms
77,840 KB
testcase_27 AC 110 ms
80,800 KB
testcase_28 AC 113 ms
81,100 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 138 ms
77,776 KB
testcase_32 AC 73 ms
76,600 KB
testcase_33 AC 135 ms
77,576 KB
testcase_34 AC 138 ms
77,716 KB
testcase_35 AC 76 ms
76,672 KB
testcase_36 AC 42 ms
55,324 KB
testcase_37 WA -
testcase_38 AC 77 ms
76,736 KB
testcase_39 AC 129 ms
80,252 KB
testcase_40 AC 137 ms
80,272 KB
testcase_41 AC 147 ms
80,308 KB
testcase_42 AC 47 ms
55,328 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
#https://note.nkmk.me/python-union-find/

N=int(input())
UF=UnionFind(N)
cnt=0
for i in range(N):
	A=list(map(int,input().split()))
	for j in range(1,len(A)):
		UF.union(i,A[j]-1)
	if A[0]==0:
		cnt+=1
if UF.size(0)==N and cnt<2:
	print("Yes")
else:
	print("No")
		
0