結果
問題 | No.583 鉄道同好会 |
ユーザー | convexineq |
提出日時 | 2021-03-04 11:19:41 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,077 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 93,308 KB |
最終ジャッジ日時 | 2024-04-15 04:30:08 |
合計ジャッジ時間 | 2,865 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,944 KB |
testcase_01 | AC | 34 ms
52,400 KB |
testcase_02 | AC | 34 ms
52,636 KB |
testcase_03 | AC | 36 ms
54,216 KB |
testcase_04 | AC | 36 ms
52,944 KB |
testcase_05 | AC | 34 ms
53,496 KB |
testcase_06 | AC | 35 ms
53,076 KB |
testcase_07 | AC | 37 ms
53,204 KB |
testcase_08 | AC | 35 ms
53,132 KB |
testcase_09 | AC | 35 ms
52,860 KB |
testcase_10 | AC | 38 ms
54,348 KB |
testcase_11 | AC | 77 ms
77,120 KB |
testcase_12 | AC | 89 ms
79,172 KB |
testcase_13 | AC | 89 ms
79,152 KB |
testcase_14 | AC | 88 ms
79,148 KB |
testcase_15 | AC | 90 ms
79,392 KB |
testcase_16 | AC | 131 ms
85,456 KB |
testcase_17 | AC | 138 ms
85,568 KB |
testcase_18 | RE | - |
ソースコード
def find_Eulerian_path_undirected(s,g,edge_valid): def dfs(v): while g[v]: u,idx = g[v].pop() if edge_valid[idx]: edge_valid[idx] -= 1 dfs(u) path.append(v) path = [] dfs(s) return path[::-1] def Eulerian_path_undirected(g,m): n = len(g) edge_valid = [1]*m deg = [len(gi)%2 for gi in g] used = [int(gi == []) for gi in g] # 辺が出ていない頂点は見ない cnt = deg.count(1) if cnt > 2: return False elif cnt == 2: s = deg.index(1) elif cnt == 0: s = used.index(0) path = find_Eulerian_path_undirected(s,g,edge_valid) if path == False: return False for v in path: used[v] = 1 if any(ui==0 for ui in used): return False else: return path n,m = map(int,input().split()) g = [[] for _ in range(n)] for i in range(m): x,y = map(int,input().split()) g[x].append((y,i)) g[y].append((x,i)) path = Eulerian_path_undirected(g,m) if path == False: print("NO") else: print("YES")