제출 #1083674

#제출 시각아이디문제언어결과실행 시간메모리
1083674LouisCheng어르신 집배원 (BOI14_postmen)Cpython 3
0 / 100
18 ms4684 KiB
import sys # sys.stdin = open("1.in", "r") n, m = map(int, input().split()) paths = [set() for _ in range(n)] for _ in range(m): a, b = map(lambda x: int(x) - 1, input().split()) paths[a].add(b) paths[b].add(a) res = [] def solve(node): while paths[node]: top = paths[node].pop() paths[top].discard(node) solve(top) res.append(node) solve(0) last = [len(res)] * n next = [len(res)] * len(res) for i in range(len(res) - 1, -1, -1): next[i] = last[res[i]] last[res[i]] = i nested = [[]] ends = [len(res) - 1] for i in range(len(res)): if ends[-1] == i: ends.pop() print(*nested.pop()) if ends and next[i] < ends[-1]: nested.append([res[i] + 1]) ends.append(next[i]) continue nested[-1].append(res[i] + 1) if next[i] < ends[-1]: nested.append([res[i] + 1]) ends.append(next[i])
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...