結果

問題 No.1605 Matrix Shape
ユーザー tonyu0tonyu0
提出日時 2022-09-21 13:15:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 120,216 KB
最終ジャッジ日時 2023-08-23 19:55:05
合計ジャッジ時間 14,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
78,840 KB
testcase_01 AC 82 ms
78,968 KB
testcase_02 AC 76 ms
74,388 KB
testcase_03 AC 82 ms
78,912 KB
testcase_04 AC 73 ms
74,288 KB
testcase_05 AC 81 ms
79,356 KB
testcase_06 AC 82 ms
78,704 KB
testcase_07 AC 78 ms
74,488 KB
testcase_08 AC 84 ms
79,012 KB
testcase_09 AC 82 ms
78,704 KB
testcase_10 AC 82 ms
78,884 KB
testcase_11 WA -
testcase_12 AC 80 ms
78,908 KB
testcase_13 AC 82 ms
78,892 KB
testcase_14 AC 81 ms
78,860 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 654 ms
120,156 KB
testcase_20 AC 769 ms
112,716 KB
testcase_21 AC 779 ms
114,912 KB
testcase_22 AC 631 ms
118,020 KB
testcase_23 AC 654 ms
120,216 KB
testcase_24 AC 646 ms
120,040 KB
testcase_25 AC 417 ms
103,112 KB
testcase_26 AC 424 ms
103,356 KB
testcase_27 AC 422 ms
102,980 KB
testcase_28 AC 423 ms
104,096 KB
testcase_29 AC 440 ms
102,916 KB
testcase_30 AC 764 ms
114,780 KB
testcase_31 AC 781 ms
116,320 KB
testcase_32 AC 801 ms
114,104 KB
testcase_33 AC 772 ms
112,888 KB
testcase_34 AC 292 ms
102,448 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())

M=200001
par=[-1]*M
def root(a):
    if par[a]<0:
        return a
    return root(par[a])
def same(a, b):
    return root(a)==root(b)
def merge(a,b):
    if same(a,b):return
    a=root(a)
    b=root(b)
    if par[a]>par[b]:a,b=b,a
    par[a]+=par[b]
    par[b]=a
def sz(a):
    return -par[root(a)]

a=[list(map(lambda x:int(x)-1, input().split())) for i in range(n)]
deg = [0]*M
V=set()
for x,y in a:
    merge(x,y)
    V.add(x)
    V.add(y)
    deg[x]-=1
    deg[y]+=1
if sz(a[0][0]) == len(V):
    st=set()
    for i in range(M):
        st.add(deg[i])
    if len(st) > 2:
        print(1)
    else:print(len(V))
else:
    print(0)
0