fork(6) download
  1. import sys
  2. sys.setrecursionlimit(5000)
  3.  
  4. def bipartite(adj, color, source):
  5.  
  6. if visited[source] == 0:
  7. visited[source] = color
  8. if color == 1: color = 2
  9. else: color = 1
  10.  
  11. for v in adj[source]:
  12.  
  13. if visited[v] == 0:
  14. bipartite(adj, color, v)
  15. elif visited[v] == visited[source]:
  16. #print 'not bipartite'
  17. return -1
  18.  
  19.  
  20.  
  21. for i in xrange(1,int(raw_input())+1):
  22. p,q = map(int, raw_input().split())
  23. global visited
  24. flag = True
  25. visited = [0]*p
  26. adj = {}
  27. for x in range(p): adj[x] = []
  28. for _ in xrange(q):
  29. m,n = map(int, raw_input().split())
  30. adj[m-1].append(n-1)
  31. adj[n-1].append(m-1)
  32.  
  33.  
  34. print 'Scenario #%i:'% i
  35. for source in range(p):
  36. if visited[source] == 0:
  37. if bipartite(adj, 1, source) == -1:
  38. print 'Suspicious bugs found!'
  39. flag = False
  40. break
  41. if flag:
  42. print 'No suspicious bugs found!'
  43.  
Success #stdin #stdout 0.02s 44632KB
stdin
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
stdout
Scenario #1:
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!