#include using namespace std; struct S { int l, r, v; }; struct T { int a, b; }; int n; vector g; int get_dist(int a, bool want){ vector done(n, false); queue> q; q.push({a,0}); while(!q.empty()){ int u = q.front().first, d = q.front().second; q.pop(); if(done[u]) continue; done[u] = true; if(g[u].v == want){ return d; } q.push({g[u].l, d+1}); q.push({g[u].r, d+1}); } return n+10; } int main() { 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 adist = get_dist(a, !g[a].v); int bdist = get_dist(b, !g[b].v); cerr << adist << ' ' << bdist << endl; if(adist != bdist){ cout << min(adist, bdist) << endl; return 0; } cout << "INDISTINGUISHABLE" << endl; return 0; }