Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ans = []
- tests = int(input())
- for curt in range(tests):
- input()
- n, m = map(int, input().split())
- p = [i for i in range(n)]
- ok = True
- for i in range(m):
- v, u = map(int, input().split())
- v -= 1
- u -= 1
- c1 = 0
- c2 = 0
- while p[v] != v:
- v = p[v]
- c1 = 1 - c1
- while p[u] != u:
- u = p[u]
- c2 = 1 - c2
- if v == u and c1 == c2:
- ok = False
- p[v] = u
- ans.append(1 if ok else -1)
- print(*ans)
Advertisement
Add Comment
Please, Sign In to add comment