#5804. [NWRRC 2021] Kaleidoscopic Route

    ID: 5804 传统题 2000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P13638图论2021Special Judge广度优先搜索 BFSICPCNWRRC

[NWRRC 2021] Kaleidoscopic Route

[NWRRC 2021] Kaleidoscopic Route

题目描述

There are $n$ cities in Kaleidostan connected with $m$ bidirectional roads. The cities are numbered from $1$ to $n$. Each road has an integer called $\textit{colorfulness}$.

Keanu wants to travel from city 11 to city nn. He wants to take the shortest\textit{shortest} route --- that is, the route with the smallest number of roads. Among all the shortest routes, he wants to take the kaleidoscopic\textit{kaleidoscopic} one --- that is, the route with the largest possible difference between the maximum and the minimum colorfulnesses of its roads. Help Keanu find such a route.

输入格式

The first line contains two integers $n$ and $m$ --- the number of cities and the number of roads ($2 \le n \le 10^5$; $1 \le m \le 2 \cdot 10^5$).

The ii-th of the following mm lines contains three integers viv_i, uiu_i, and cic_i --- the indices of the cities connected by the ii-th road, and the colorfulness of the ii-th road (1≤vi,ui≤n1 \le v_i, u_i \le n; vi≠uiv_i \neq u_i; 0≤ci≤1090\le c_i \le 10^9).

Each pair of cities is connected by at most one road. It is guaranteed that you can travel from any city to any other city using the roads.

输出格式

In the first line, print a single integer $k$ --- the number of roads in the required route.

In the second line, print k+1k+1 integers c0,c1,…,ckc_0, c_1, \ldots, c_k --- the sequence of cities on the route (1≤ci≤n1 \le c_i \le n; c0=1c_0 = 1; ck=nc_k = n).

6 8
1 5 2
5 2 5
3 5 4
1 3 10
3 4 6
4 5 7
4 6 8
2 6 1
3
1 5 4 6

提示

![](https://cdn.luogu.com.cn/upload/image_hosting/bun5oktu.png)

In the example test, the required route consists of 33 roads, and the difference between the maximum and the minimum colorfulnesses of its roads is 8−2=68-2=6. 标签: P13638|图论|2021|Special Judge|广度优先搜索 BFS|ICPC|NWRRC

来源

P13638|[NWRRC 2021] Kaleidoscopic Route