結果

問題 No.1605 Matrix Shape
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-17 11:41:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 839,632 KB
最終ジャッジ日時 2023-09-21 04:37:01
合計ジャッジ時間 15,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
80,708 KB
testcase_01 WA -
testcase_02 AC 83 ms
80,008 KB
testcase_03 WA -
testcase_04 AC 84 ms
79,772 KB
testcase_05 AC 88 ms
80,368 KB
testcase_06 WA -
testcase_07 AC 85 ms
79,880 KB
testcase_08 WA -
testcase_09 AC 91 ms
80,660 KB
testcase_10 AC 89 ms
80,744 KB
testcase_11 AC 87 ms
80,640 KB
testcase_12 WA -
testcase_13 AC 88 ms
80,752 KB
testcase_14 AC 90 ms
80,704 KB
testcase_15 AC 88 ms
80,768 KB
testcase_16 AC 88 ms
80,776 KB
testcase_17 AC 87 ms
80,636 KB
testcase_18 AC 89 ms
80,900 KB
testcase_19 AC 990 ms
289,664 KB
testcase_20 WA -
testcase_21 AC 849 ms
200,448 KB
testcase_22 AC 730 ms
199,768 KB
testcase_23 WA -
testcase_24 AC 935 ms
213,864 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 243 ms
100,860 KB
testcase_28 AC 238 ms
100,532 KB
testcase_29 AC 244 ms
100,796 KB
testcase_30 WA -
testcase_31 AC 506 ms
106,632 KB
testcase_32 WA -
testcase_33 AC 530 ms
132,624 KB
testcase_34 WA -
testcase_35 MLE -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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(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)
elif tmp == 2: print(1)
else: print(0)
0