結果
問題 |
No.1605 Matrix Shape
|
ユーザー |
|
提出日時 | 2021-07-17 12:01:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 822 ms / 2,000 ms |
コード長 | 609 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 282,204 KB |
最終ジャッジ日時 | 2024-07-06 23:31:41 |
合計ジャッジ時間 | 10,112 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
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)