#include "testlib.h" #include #include int main(int argc, char* argv[]) { registerValidation(argc, argv); int n = inf.readInt(2, 200'000); inf.readEoln(); std::vector a(n - 1), b(n - 1), c(n - 1); for(size_t i = 0; i + 1 < n; i++) { a[i] = inf.readInt(1, n - 1); inf.readSpace(); b[i] = inf.readInt(a[i] + 1, n); inf.readSpace(); c[i] = inf.readInt(0, (1 << 30) - 1); inf.readEoln(); } inf.readEof(); { // check is_tree std::vector> g(n); for(size_t i = 0; i + 1 < n; i++) { g[--a[i]].push_back(i); g[--b[i]].push_back(i); } std::vector used(n); auto dfs = [&](auto&& dfs, int v, int par) -> void { if(used[v]) return; used[v] = 1; for(int id: g[v]) { int to = a[id] ^ b[id] ^ v; if(to == par) continue; dfs(dfs, to, v); } }; dfs(dfs, 0, -1); assert(std::accumulate(begin(used), end(used), 0) == n); } return 0; }