Submission #1330535

#TimeUsernameProblemLanguageResultExecution timeMemory
1330535akshar_7Senior Postmen (BOI14_postmen)Pypy 3
55 / 100
813 ms236424 KiB
from sys import stdin
input = stdin.readline

def euler(x):
  ans = []
  vis = [False]*m
  s = [x]
  while s:
    u = s[-1]
    while g[u] and vis[g[u][-1][1]]: g[u].pop()
    if g[u]:
      v,j = g[u].pop()
      vis[j] = True
      s.append(v)
    else:
      y = s.pop()
      ans.append(y)
      #idx.append(k)
  return ans

#n = int(input())
n,m = map(int, input().split())
#a = [int(i) for i in input().split()]
#b = [int(i) for i in input().split()]
#c = [int(i) for i in input().split()]
#c = [list(i) for i in input().split()]
#b = [int(i) for i in input().split()]
#s = input().strip()
g = [[] for i in range(n+1)]
for i in range(m):
  u,v = map(int, input().split())
  g[u].append((v,i))
  g[v].append((u,i))
ans = euler(1)
#print(ans)
onstk = [False]*(n+1)
s = []
for x in ans:
  if onstk[x]:
    b = [x]
    while s[-1] !=x:
      y = s.pop()
      onstk[y] = False
      b.append(y)
    print(*b)
  else:
    onstk[x] = True
    s.append(x)

Compilation message (stdout)

Compiling 'postmen.py'...

=======
  adding: __main__.pyc (deflated 35%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...