#P16024. [ICPC 2021 NAC] TraveLog

[ICPC 2021 NAC] TraveLog

题目描述

After a long time apart, Alice and Bob have reunited. They live in a country with nn cities, creatively named city 11 to city nn. Bob drove from his home in city 11 to Alice’s home in city nn.

When Alice asked Bob which path he took, he was stunned to find he didn’t remember. Bob is efficient, and drove without stopping, and knows there is no path faster than the one he took. He also has a brand new National Adventuring Company (NAC) TraveLog! Every time Bob drives through a city, the TraveLog records the time between when he left city 11 and when he arrived in the current city.

:::align{center} :::

In the above layout, there are two possible fastest paths Bob can take from city 11 to city nn: 12351 \rightarrow 2 \rightarrow 3 \rightarrow 5 or 1451 \rightarrow 4 \rightarrow 5. Both paths take a total of 99 units of time. The first path would have a TraveLog of 0,3,7,90, 3, 7, 9, and the second would have a TraveLog of 0,5,90, 5, 9.

Unfortunately, the memory in Bob’s TraveLog is corrupted. Bob thinks that some of the times are gone, and the remaining times are shuffled arbitrarily. Given what remains of the TraveLog, can you reconstruct Bob’s path?

输入格式

The first line of input contains three integers nn (2n21052 \le n \le 2 \cdot 10^5), mm (1m31051 \le m \le 3 \cdot 10^5) and dd (1dn1 \le d \le n), where nn is the number of cities in the country, mm is the number of one-way roads between those cities, and dd is the number of times remaining in Bob’s corrupted TraveLog. The cities are identified by number, 11 through nn. Bob lives in city 11, and Alice lives in city nn.

Each of the next mm lines contains three integers uu, vv (1u,vn,uv1 \le u, v \le n, u \ne v) and hh (1h1061 \le h \le 10^6). Each line describes a one-way road from city uu to city vv that takes hh units of time to traverse. There is guaranteed to be at least one path from city 11 to city nn. There may be several roads between any given pair of cities.

Each of the next dd lines contains a single integer tt (0t10180 \le t \le 10^{18}). This is what remains of Bob’s TraveLog. Each line is a record of the amount of time Bob took driving from city 11 to another city on his path. These values are guaranteed to be distinct.

输出格式

The output format depends on the number of paths consistent with Bob’s TraveLog.

  • If there is no path consistent with Bob’s TraveLog, output 00.
  • If multiple paths are consistent with Bob’s TraveLog, output 11.
  • Otherwise, on the first line, output the number of cities on Bob’s path. On subsequent lines, output the cities Bob visited, one per line, in the order he visited them.
5 5 2
1 2 3
2 3 4
3 5 2
1 4 5
4 5 4
5
9
3
1
4
5
6 8 2
1 2 1
2 3 2
3 6 8
1 4 3
4 5 4
5 6 4
5 2 7
1 6 13
0
3
1
2 1 1
1 2 10
5
0