Under construction

Still being built. Things may change

Driver Disagreement

Time limit2sMemory limit512 MB

Summary
Given a map where each intersection has left and right exits and a tower flag, find the fewest shared turns from A and B that expose different tower visibility.
Level

Medium7 of 10

Topics
Graph, BFS, Union-find
Solved
No attempts yet

Statement

Alice and Bob are travelling in Italy by car, and they took a wrong turn. Now they are stuck in the city centre of Pisa. You need an allowance to drive in the city centre, so they risk getting a fine. They have a map but no GPS. The map lists all intersections. At each intersection you can turn either left or right. You cannot go straight or make a U-turn, because many streets are one-way.

Alice thinks they are at intersection AA, while Bob thinks they are at intersection BB. They want to find out who is right. They plan an experiment: they trace the same sequence of turns on the map, once starting from AA and once starting from BB. The map marks the intersections from which the leaning tower of Pisa is visible. As soon as the tower should be visible for one of them but not for the other, they look out of the window and see who is right. You may assume exactly one of them is right.

Find the minimal number of turns needed to show who is right.

Input

The first line contains three integers nn, AA, and BB, where 2≤n≤1052 \le n \le 10^5, 0≤A,B<n0 \le A, B < n, and A≠BA \ne B.

Then follow nn lines. The ii-th of these lines contains three integers lil_i, rir_i, and tit_i. At intersection ii, a left turn leads to lil_i and a right turn leads to rir_i. ti=1t_i = 1 if the leaning tower of Pisa is visible from intersection ii, and ti=0t_i = 0 otherwise.

Output

Print the minimal number of turns it takes to show either person correct. If no experiment can tell whether Alice or Bob is correct, print indistinguishable.

Examples3

  1. Example 1

    Input
    3 1 2
    1 2 1
    0 2 0
    0 1 0
    
    Expected output
    indistinguishable
    
  2. Example 2

    Input
    2 0 1
    1 1 1
    0 0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    3 1 2
    1 2 0
    2 0 1
    0 1 1
    
    Expected output
    1