結果

問題 No.2202 贅沢てりたまチキン
ユーザー ニックネームニックネーム
提出日時 2023-02-03 21:35:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,078 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 17,728 KB
最終ジャッジ日時 2023-09-15 17:11:18
合計ジャッジ時間 13,907 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,952 KB
testcase_01 AC 16 ms
7,944 KB
testcase_02 AC 16 ms
7,852 KB
testcase_03 AC 16 ms
7,924 KB
testcase_04 AC 15 ms
7,924 KB
testcase_05 AC 15 ms
7,796 KB
testcase_06 AC 16 ms
7,832 KB
testcase_07 AC 16 ms
7,852 KB
testcase_08 AC 15 ms
7,808 KB
testcase_09 AC 15 ms
7,924 KB
testcase_10 AC 98 ms
11,108 KB
testcase_11 AC 15 ms
7,820 KB
testcase_12 AC 16 ms
7,792 KB
testcase_13 AC 15 ms
7,944 KB
testcase_14 AC 908 ms
11,364 KB
testcase_15 AC 908 ms
11,320 KB
testcase_16 AC 850 ms
17,724 KB
testcase_17 AC 869 ms
17,728 KB
testcase_18 AC 426 ms
12,948 KB
testcase_19 AC 484 ms
17,712 KB
testcase_20 AC 892 ms
17,556 KB
testcase_21 AC 887 ms
17,656 KB
testcase_22 AC 733 ms
8,272 KB
testcase_23 AC 763 ms
8,480 KB
testcase_24 AC 734 ms
8,272 KB
testcase_25 AC 1,078 ms
15,208 KB
testcase_26 AC 927 ms
11,464 KB
testcase_27 AC 904 ms
11,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UF:
    def __init__(self,n):
        self.p = [-1]*n
    def f(self,x):
        if self.p[x]<0: return x
        else: self.p[x] = self.f(self.p[x]); return self.p[x]
    def u(self,x,y):
        x = self.f(x); y = self.f(y)
        if x==y: return
        if -self.p[x]<-self.p[y]: x,y = y,x
        self.p[x] += self.p[y]; self.p[y] = x
    def s(self,x,y): return self.f(x) == self.f(y)
n,m = map(int,input().split())
uf = UF(2*n)
for _ in range(m):
    a,b = map(int,input().split())
    uf.u(a-1,b-1+n); uf.u(a-1+n,b-1)
ans = "Yes"
for i in range(n):
    if not uf.s(i,i+n): ans = "No"
print(ans)
0