#include using namespace std; using ll = long long; using ull = unsigned long long; struct S { int l, r, v; }; struct T { int a, b; }; 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, ull, pair_hash> m; constexpr int K = 900; array, 100000> m; // Hash node u up to distance d. ull 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) + 13245*calc(g[u].r, d-1);// + 91841 * g[u].v; x = v+1; return v; } int main() { auto start = chrono::high_resolution_clock::now(); int a, b; cin >> n >> a >> b; g.resize(n); for(auto &x : g) cin >> x.l >> x.r >> x.v; if(g[a].v != g[b].v) { cout << 0 << endl; return 0; } int I = 0; //m.reserve(2e7); for(auto &x : m) x.fill(0); for(int d = 0; d>(now-start).count() > 1.0) break; auto ha = calc(a,d); auto hb = calc(b,d); if(ha != hb){ cout << d << endl; return 0; } } cout << "INDISTINGUISHABLE" << endl; return 0; }