結果
| 問題 | 
                            No.1605 Matrix Shape
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-07-17 11:40:57 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 571 bytes | 
| コンパイル時間 | 285 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 282,152 KB | 
| 最終ジャッジ日時 | 2024-07-06 23:11:26 | 
| 合計ジャッジ時間 | 13,085 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 16 WA * 18 | 
ソースコード
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)
else: print(1)