AT_abc485_e [ABC485E] Colorful Route
Description
There are $ N $ cities and $ M $ **one-way** roads. The $ i $ -th road leads from city $ U_i $ to city $ V_i $ and is painted in color $ C_i $ .
You want to travel from city $ 1 $ to city $ N $ by repeatedly traversing roads. However, you must not traverse roads painted in the same color twice in a row.
Determine whether it is possible to reach city $ N $ from city $ 1 $ , and if it is possible, find the minimum possible number of times you traverse a road.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ M $ $ U_1 $ $ V_1 $ $ C_1 $ $ U_2 $ $ V_2 $ $ C_2 $ $ \vdots $ $ U_M $ $ V_M $ $ C_M $
Output Format
If it is impossible to reach city $ N $ from city $ 1 $ , print `-1`. Otherwise, print the minimum possible number of times you traverse a road.
Explanation/Hint
### Sample Explanation 1
Let road $ i $ denote the $ i $ -th road. You can reach city $ 6 $ by traversing roads $ 1, 2, 5, 4 $ in this order.
### Constraints
- $ 2 \leq N \leq 2 \times 10^5 $
- $ 1 \leq M \leq 2 \times 10^5 $
- $ 1 \leq U_i, V_i \leq N $
- $ U_i \neq V_i $
- $ 1 \leq C_i \leq M $
- All input values are integers.