結果

問題 No.1605 Matrix Shape
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-17 11:39:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 561 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 290,380 KB
最終ジャッジ日時 2023-09-21 04:35:09
合計ジャッジ時間 14,471 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
79,016 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 AC 79 ms
78,200 KB
testcase_05 AC 85 ms
79,264 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 84 ms
79,116 KB
testcase_10 AC 83 ms
79,124 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 AC 84 ms
79,188 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,008 ms
290,380 KB
testcase_20 WA -
testcase_21 AC 829 ms
200,784 KB
testcase_22 AC 697 ms
199,000 KB
testcase_23 WA -
testcase_24 AC 906 ms
213,732 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 236 ms
100,908 KB
testcase_28 AC 235 ms
100,816 KB
testcase_29 AC 239 ms
100,880 KB
testcase_30 WA -
testcase_31 AC 495 ms
106,652 KB
testcase_32 WA -
testcase_33 AC 519 ms
131,908 KB
testcase_34 WA -
testcase_35 RE -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
cnt = [0 for i in range(2 * 10 ** 5)]
G = [[] for i in range(n)]
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(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(n)
else: print(1)
0