#P1811. 最短路

最短路

Description

Given an undirected graph with NN vertices and MM edges, where each edge has weight 11.

You are also given KK ordered triples (A,B,C)(A,B,C), meaning that after moving from AA to BB, you are not allowed to move to CC. Note that the triples are ordered; for example, it is allowed to go from BB to AA and then to CC.

Under the constraints given by the KK triples, find the shortest path from node 11 to node NN, and output any valid path. A Check will verify your output.

Input Format

The first line contains three integers NN, MM, KK, as described above.

Each of the next MM lines contains two integers AA, BB, indicating there is an edge between AA and BB.

Each of the next KK lines contains three integers (A,B,C)(A,B,C) describing one triple.

Output Format

Output consists of two lines. The first line contains a single integer SS, the length of the shortest path.

The second line contains S+1S+1 integers, the sequence of nodes visited from 11 to NN.

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

Hint

For 40% of the testdata, N10N \le 10, M20M \le 20, K5K \le 5.

For 100% of the testdata, N3000N \le 3000, M20000M \le 20000, K100000K \le 100000.

Translated by ChatGPT 5