#include #include "testlib.h" using namespace std; struct UnionFind { vector size, parents; UnionFind() {} UnionFind(int n) { size.resize(n, 0); parents.resize(n, 0); for (int i = 0; i < n; i++) { makeTree(i); } } void makeTree(int x) { parents[x] = x; size[x] = 1; } bool isSame(int x, int y) { return findRoot(x) == findRoot(y); } bool unite(int x, int y) { x = findRoot(x); y = findRoot(y); if (x == y) return false; if (size[x] > size[y]) { parents[y] = x; size[x] += size[y]; } else { parents[x] = y; size[y] += size[x]; } return true; } int findRoot(int x) { if (x != parents[x]) { parents[x] = findRoot(parents[x]); } return parents[x]; } int treeSize(int x) { return size[findRoot(x)]; } }; int main() { registerValidation(); int N; inf.readInt(2, 100000, "N"); inf.readEoln(); UnionFind uni(N); int count = 0; map, int> Map; for (int i = 0; i < N * (N - 1) / 2; i++) { int a = inf.readInt(1, N, "a"); inf.readSpace(); int b = inf.readInt(1, N, "a"); inf.readSpace(); string S = inf.readToken("[0-9]{1, 101}", "S"); inf.readEoln(); if (Map[make_pair(a, b)] == 1) cout << -1 << endl; Map[make_pair(a, b)]++; a--; b--; if (S.size() == 101) { for (int i = 2; i < 101; i++) { if (S[i] != '0') cout << -1 << endl; } } if (!uni.isSame(a, b)) { uni.unite(a, b); count++; if (count == N - 1) { cout << S << endl; return 0; } } } inf.readEof(); }