#include using namespace std; struct S { int l, r, v; }; struct T { int a, b; }; int main() { int n, a, b; cin >> n >> a >> b; vector g(n); for(auto &x : g) cin >> x.l >> x.r >> x.v; stack q; if(g[a].v != g[b].v) { cout << 0 << endl; return 0; } set> done; q.push({a, b, 0}); int I = 0; while(!q.empty() && ++I < 1000000) { int l = q.top().l, r = q.top().r, d = q.top().v + 1; if(!done.insert({l,r}).second) continue; q.pop(); for(T t : {T{g[l].r, g[r].r}, T{g[l].l, g[r].l}}) { int a = t.a, b = t.b; if(g[a].v != g[b].v) { cout << d << endl; return 0; } q.push({a, b, d}); } } cout << "INDISTINGUISHABLE" << endl; return 0; }