#include using namespace std; using ll = long long; struct S { int l, r, v; }; struct pair_hash { std::size_t operator()(const std::pair& p) const { return std::hash()(p.first) ^ (std::hash()(p.second) << 3); } }; int n; vector g; unordered_map, ll, pair_hash> m; ll calc(int u, int d){ if(d == 0) return g[u].v; auto&x = m[{u,d}]; if(x > 0) return x-1; auto v = calc(g[u].l, d-1) + calc(g[u].r, d-1); x = v+1; return v; } int main() { int a, b; cin >> n >> a >> b; g.resize(n); for(auto &x : g) cin >> x.l >> x.r >> x.v; // Return the lowest distance at which the number of 1s differs. auto start = chrono::high_resolution_clock::now(); for(int d = 0; d <= n; ++d){ auto now = chrono::high_resolution_clock::now(); if(chrono::duration>(now-start).count() > 1.5) break; if(calc(a, d) != calc(b, d)){ cout << d << endl; return 0; } } cout << "INDISTINGUISHABLE" << endl; return 0; }