結果

問題 No.1605 Matrix Shape
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-17 11:43:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 604 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 290,360 KB
最終ジャッジ日時 2023-09-21 04:38:21
合計ジャッジ時間 14,116 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
80,556 KB
testcase_01 AC 90 ms
80,792 KB
testcase_02 AC 83 ms
79,960 KB
testcase_03 WA -
testcase_04 AC 83 ms
79,872 KB
testcase_05 AC 87 ms
80,816 KB
testcase_06 WA -
testcase_07 AC 84 ms
79,856 KB
testcase_08 WA -
testcase_09 AC 89 ms
80,704 KB
testcase_10 AC 90 ms
80,756 KB
testcase_11 AC 89 ms
80,740 KB
testcase_12 WA -
testcase_13 AC 88 ms
80,748 KB
testcase_14 AC 91 ms
80,724 KB
testcase_15 AC 88 ms
80,556 KB
testcase_16 AC 87 ms
80,816 KB
testcase_17 AC 86 ms
80,660 KB
testcase_18 AC 86 ms
80,576 KB
testcase_19 AC 1,021 ms
290,360 KB
testcase_20 WA -
testcase_21 AC 717 ms
192,480 KB
testcase_22 AC 721 ms
199,008 KB
testcase_23 WA -
testcase_24 AC 914 ms
212,564 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 248 ms
104,428 KB
testcase_28 AC 235 ms
100,804 KB
testcase_29 AC 237 ms
100,984 KB
testcase_30 WA -
testcase_31 AC 497 ms
108,124 KB
testcase_32 WA -
testcase_33 AC 516 ms
139,596 KB
testcase_34 WA -
testcase_35 AC 674 ms
188,900 KB
testcase_36 AC 477 ms
186,484 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(n)
elif tmp == 2: print(1)
else: print(0)
0