結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
78,580 KB
testcase_01 AC 80 ms
78,456 KB
testcase_02 AC 79 ms
74,660 KB
testcase_03 AC 81 ms
78,584 KB
testcase_04 AC 80 ms
74,488 KB
testcase_05 AC 80 ms
78,720 KB
testcase_06 AC 81 ms
78,552 KB
testcase_07 AC 78 ms
74,340 KB
testcase_08 AC 82 ms
78,668 KB
testcase_09 AC 81 ms
78,668 KB
testcase_10 AC 83 ms
78,776 KB
testcase_11 WA -
testcase_12 AC 81 ms
78,624 KB
testcase_13 AC 82 ms
78,604 KB
testcase_14 AC 81 ms
78,672 KB
testcase_15 AC 83 ms
78,628 KB
testcase_16 AC 80 ms
78,544 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 673 ms
120,228 KB
testcase_20 AC 759 ms
112,036 KB
testcase_21 AC 765 ms
115,244 KB
testcase_22 AC 648 ms
118,104 KB
testcase_23 AC 656 ms
120,280 KB
testcase_24 AC 646 ms
120,108 KB
testcase_25 AC 423 ms
103,008 KB
testcase_26 AC 421 ms
103,516 KB
testcase_27 AC 426 ms
103,216 KB
testcase_28 AC 422 ms
104,096 KB
testcase_29 AC 441 ms
103,044 KB
testcase_30 AC 765 ms
114,808 KB
testcase_31 AC 773 ms
116,608 KB
testcase_32 AC 786 ms
113,700 KB
testcase_33 AC 770 ms
112,960 KB
testcase_34 AC 288 ms
102,292 KB
testcase_35 AC 567 ms
116,596 KB
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):
    # とりあえず連結
    start=0
    end=0
    for x in deg:
        if x==1:
            end+=1
        elif x==-1:
            start+=1
    if start==1 and end==1:print(1)
    elif start==0 and end==0:print(len(V))
    else: print(0)
else:
    print(0)
0