SHARE
TWEET

Построение

boris-vlasenko Jul 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #166 Построение
  2. from sys import setrecursionlimit
  3. setrecursionlimit(10**9)
  4.  
  5. def dfs (v):
  6.     global check, edge, color
  7.     color[v] = 1
  8.     for i in edge[v]:
  9.         if color[i] == 0:
  10.             dfs(i)
  11.         elif color[i] == 1:
  12.             check = False
  13.     color[v] = 2
  14.     edge_chern.append(v)
  15.  
  16.  
  17. n, m = map(int,input().split())
  18. edge = [[] for i in range(n+1)]
  19. for i in range(m):
  20.     a, b = map(int,input().split())
  21.     edge[a].append(b)
  22. edge_chern = []
  23. color = [ 0 for i in range(n+1)]
  24. check = True
  25. for i in range(1,n+1):
  26.     if color[i] == 0:
  27.         dfs(i)
  28. if check:
  29.     print('Yes')
  30.     print(*edge_chern[::-1])
  31. else:
  32.     print('No')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top