Submission #1083645

#TimeUsernameProblemLanguageResultExecution timeMemory
1083645LouisChengSenior Postmen (BOI14_postmen)Cpython 3
0 / 100
23 ms6212 KiB
import bisect import sys # sys.stdin = open("1.in", "r") sys.setrecursionlimit(int(5e5) + 1) 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) next = [[] for _ in range(n)] for i in range(len(res)): next[res[i]].append(i) nested = [[]] ends = [len(res) - 1] for i in range(len(res)): if ends[-1] == i: ends.pop() print(*nested.pop()) continue nested[-1].append(res[i] + 1) less = bisect.bisect_left(next[res[i]], ends[-1]) - 1 if next[res[i]][less] != i: nested.append([res[i] + 1]) ends.append(next[res[i]][less])
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...