Guest User

Untitled

a guest
Jul 21st, 2019
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Even Paths
  2.  
  3. You are given a directed acyclic graph with no multiple
  4. edges or self loops.You are given also given a source node X as input. For each node Y, find the number of paths that start at X and end at Y, such that the number of nodes visited along that path is even (including X and Y).
  5.  
  6. Note :
  7. The path from X to X consists of only one node and hence the number of nodes visited is odd.Hence there are 0 paths for X
  8. to X which consist of even number of nodes.
  9.  
  10. Input:
  11. First line contains T, the number of test cases
  12. For each test case:
  13. First line contains three space separated integers N, M and X (number of nodes ,number of edges and the source
  14. node respectively)
  15. Next M line contains two space separated integers u and v (there is a directed edge from u to v)
  16.  
  17. Output:
  18. For each test case:
  19. A new line containing N space separated integers, where the i-th element is the answer for node i, mod 1000000007
  20.  
  21. Constraints:
  22. 1 <= T <= 20
  23. 1 <= N <= 10 5
  24. 1 <= M <= min(10 5 , (N*(N-1))/2)
  25. 1 <= u, v <= N
  26. 1 <= X <= N
  27.  
  28. Sample Input
  29. 2
  30. 5 4 1
  31. 1 2
  32. 2 3
  33. 1 4
  34. 3 5
  35. 5 5 1
  36. 1 2
  37. 2 3
  38. 1 4
  39. 3 5
  40. 1 5
  41.  
  42. Sample Output
  43. 0 1 0 1 1
  44. 0 1 0 1 2
Add Comment
Please, Sign In to add comment