結果

問題 No.2202 贅沢てりたまチキン
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-02-03 23:22:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 525 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 84,960 KB
最終ジャッジ日時 2023-09-15 19:39:00
合計ジャッジ時間 6,913 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,916 KB
testcase_01 AC 72 ms
71,368 KB
testcase_02 AC 73 ms
71,176 KB
testcase_03 AC 70 ms
71,428 KB
testcase_04 AC 72 ms
71,288 KB
testcase_05 AC 73 ms
71,432 KB
testcase_06 AC 72 ms
71,420 KB
testcase_07 AC 72 ms
71,064 KB
testcase_08 AC 73 ms
71,224 KB
testcase_09 AC 72 ms
71,292 KB
testcase_10 AC 74 ms
74,392 KB
testcase_11 AC 72 ms
71,296 KB
testcase_12 AC 73 ms
71,428 KB
testcase_13 AC 71 ms
71,356 KB
testcase_14 AC 228 ms
81,628 KB
testcase_15 AC 229 ms
81,588 KB
testcase_16 AC 216 ms
81,596 KB
testcase_17 AC 222 ms
82,008 KB
testcase_18 AC 167 ms
83,012 KB
testcase_19 AC 165 ms
81,508 KB
testcase_20 AC 244 ms
81,784 KB
testcase_21 AC 245 ms
81,720 KB
testcase_22 AC 225 ms
78,936 KB
testcase_23 AC 320 ms
80,512 KB
testcase_24 AC 267 ms
79,156 KB
testcase_25 AC 525 ms
84,960 KB
testcase_26 AC 233 ms
81,560 KB
testcase_27 AC 223 ms
81,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]


n,m = map(int,input().split())
uf = Unionfind(n*2)
for i in range(m):
    a,b = [int(x)-1 for x in input().split()]
    uf.union(a,b+n)
    uf.union(a+n,b)


for i in range(n):
    if uf.same(i,i+n):
        continue
    print("No")
    exit()
print("Yes")
0