bzoj#P2644. Pku3967 Ideal Path

Pku3967 Ideal Path

题目描述

New labyrinth attraction is open in New Lostland amusement park. The labyrinth consists of nn rooms connected by mm passages. Each passage is colored into some color cic_{i}. Visitors of the labyrinth are dropped from the helicopter to the room number 11 and their goal is to get to the labyrinth exit located in the room number nn.
Labyrinth owners are planning to run a contest tomorrow. Several runners will be dropped to the room number 11. They will run to the room number nn writing down colors of passages as they run through them. The contestant with the shortest sequence of colors is the winner of the contest. If there are several contestants with the same sequence length, the one with the ideal path is the winner. The path is the ideal path if its color sequence is the lexicographically smallest among shortest paths. Andrew is preparing for the contest. He took a helicopter tour above New Lostland and made a picture of the labyrinth. Your task is to help him find the ideal path from the room number 11 to the room number nn that would allow him to win the contest.

Note:

  • A sequence (a1,a2,,aka_{1}, a_{2},\dotsb, a_{k}) is lexicographically smaller than a sequence (b1,b2,,bkb_{1}, b_{2},\dotsb, b_{k}) if there exists ii such that ai<bia_{i} < b_{i}, and aj=bja_{j} = b_{j} for all j<ij < i.

给定无向图(有重边)每条边有一种颜色,边权为 11,让你找到从 11nn 的最短路,并且经过的边的颜色组成的序列的字典序最小。

输入格式

The first line of the input file contains integers nn and mm —the number of rooms and passages, respectively. The following m lines describe passages, each passage is described with three integer numbers: ai,bia_{i},b_{i},and cic_{i} — the numbers of rooms it connects and its color. Each passage can be passed in either direction. Two rooms can be connected with more than one passage, there can be a passage from a room to itself. It is guaranteed that it is possible to reach the room number n from the room number 11.

输出格式

The first line of the output file must contain kk — the length of the shortest path from the room number 11 to the room number nn. The second line must contain kk numbers — the colors of passages in the order they must be passed in the ideal path.

样例

4 6
1 2 1
1 3 2
3 4 3
2 3 1
2 4 4
3 1 1

2
1 3

数据规模与约定

对于 100%100\% 的数据,2n1×1052 \leq n \leq 1 \times 10^51m2×1051 \leq m \leq 2 \times 10^51ai,bin1 \leq a_{i}, b_{i} \leq n1ci1091 \leq c_{i} \leq 10^{9}

题目来源

Pku3967