結果

問題 No.1605 Matrix Shape
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-17 12:01:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,030 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 289,852 KB
最終ジャッジ日時 2023-09-21 04:58:23
合計ジャッジ時間 14,108 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
80,496 KB
testcase_01 AC 88 ms
80,664 KB
testcase_02 AC 88 ms
79,856 KB
testcase_03 AC 91 ms
80,744 KB
testcase_04 AC 85 ms
79,972 KB
testcase_05 AC 87 ms
80,612 KB
testcase_06 AC 88 ms
80,576 KB
testcase_07 AC 83 ms
79,988 KB
testcase_08 AC 87 ms
80,756 KB
testcase_09 AC 85 ms
80,740 KB
testcase_10 AC 89 ms
80,692 KB
testcase_11 AC 88 ms
80,596 KB
testcase_12 AC 88 ms
80,752 KB
testcase_13 AC 88 ms
80,612 KB
testcase_14 AC 88 ms
80,692 KB
testcase_15 AC 87 ms
80,568 KB
testcase_16 AC 88 ms
80,712 KB
testcase_17 AC 86 ms
80,692 KB
testcase_18 AC 87 ms
80,592 KB
testcase_19 AC 1,030 ms
289,852 KB
testcase_20 AC 860 ms
201,604 KB
testcase_21 AC 731 ms
193,292 KB
testcase_22 AC 750 ms
199,364 KB
testcase_23 AC 946 ms
240,200 KB
testcase_24 AC 921 ms
213,188 KB
testcase_25 AC 240 ms
100,784 KB
testcase_26 AC 238 ms
100,732 KB
testcase_27 AC 248 ms
104,520 KB
testcase_28 AC 247 ms
100,704 KB
testcase_29 AC 247 ms
100,908 KB
testcase_30 AC 532 ms
108,320 KB
testcase_31 AC 534 ms
108,008 KB
testcase_32 AC 544 ms
130,944 KB
testcase_33 AC 522 ms
139,116 KB
testcase_34 AC 229 ms
105,264 KB
testcase_35 AC 674 ms
190,092 KB
testcase_36 AC 477 ms
186,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
cnt = [0 for i in range(2 * 10 ** 5)]
G = [[] for i in range(2 * 10 ** 5)]
s = set()
for _ in range(n):
    h, w = map(int, input().split())
    G[h - 1].append(w - 1)
    G[w - 1].append(h - 1)
    cnt[h - 1] += 1
    cnt[w - 1] -= 1
    s.add(h - 1)
    s.add(w - 1)
vis = [0] * (2 * 10 ** 5)
def dfs(v):
    vis[v] = 1
    for u in G[v]:
        if not vis[u]: dfs(u)
dfs(list(s)[0])
if not all(vis[i] for i in s): exit(print(0))
tmp = sum(abs(cnt[i]) for i in range(2 * 10 ** 5)) 
if tmp == 0: print(len(s))
elif tmp == 2: print(1)
else: print(0)
0