using System.Linq; using System.Collections.Generic; using System; public class P { public int xor { get; set; } public int to { get; set; } } public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var aa = new List

[n]; for (int i = 0; i < n; i++) aa[i] = new List

(); var check = new int[m, 3]; for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var t0 = int.Parse(line[0]) - 1; var t1 = int.Parse(line[1]) - 1; var t2 = int.Parse(Console.ReadLine().Trim()); aa[t0].Add(new P { to = t1, xor = t2 }); aa[t1].Add(new P { to = t0, xor = t2 }); check[i, 0] = t0; check[i, 1] = t1; check[i, 2] = t2; } getAns(n, m, aa, check); } static void getAns(int n, int m, List

[] aa, int[,] check) { var ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = -1; var q = new Queue(); for (int i = 0; i < n; i++) { if (ans[i] == -1) { ans[i] = 0; q.Enqueue(i); while (q.Count() > 0) { var w = q.Dequeue(); foreach (var x in aa[w]) { var t = ans[w] ^ x.xor; if (ans[x.to] == -1) { ans[x.to] = t; q.Enqueue(x.to); } } } } } var ok = true; for (int i = 0; i < m; i++) { if ((ans[check[i, 0]] ^ ans[check[i, 1]]) != check[i, 2]) { ok = false; break; } } if (ok) Console.WriteLine(string.Join("\n", ans)); else Console.WriteLine(-1); } }