CF59E.Shortest Path

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Ancient Berland there were nn cities and mm two-way roads of equal length. The cities are numbered with integers from 11 to nn inclusively. According to an ancient superstition, if a traveller visits three cities aia_{i} , bib_{i} , cic_{i} in row, without visiting other cities between them, a great disaster awaits him. Overall there are kk such city triplets. Each triplet is ordered, which means that, for example, you are allowed to visit the cities in the following order: aia_{i} , cic_{i} , bib_{i} . Vasya wants to get from the city 11 to the city nn and not fulfil the superstition. Find out which minimal number of roads he should take. Also you are required to find one of his possible path routes.

输入格式

The first line contains three integers nn , mm , kk ( 2<=n<=3000,1<=m<=20000,0<=k<=1052<=n<=3000,1<=m<=20000,0<=k<=10^{5} ) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly.

Then follow mm lines each containing two integers xix_{i} , yiy_{i} ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n ) which are the road descriptions. The road is described by the numbers of the cities it joins. No road joins a city with itself, there cannot be more than one road between a pair of cities.

Then follow kk lines each containing three integers aia_{i} , bib_{i} , cic_{i} ( 1<=ai,bi,ci<=n1<=a_{i},b_{i},c_{i}<=n ) which are the forbidden triplets. Each ordered triplet is listed mo more than one time. All three cities in each triplet are distinct.

City nn can be unreachable from city 11 by roads.

输出格式

If there are no path from 11 to nn print -1. Otherwise on the first line print the number of roads dd along the shortest path from the city 11 to the city nn . On the second line print d+1d+1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 11 and end in the city nn .

输入输出样例

  • 输入#1

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

    输出#1

    2
    1 3 4
    
  • 输入#2

    3 1 0
    1 2
    

    输出#2

    -1
    
  • 输入#3

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

    输出#3

    4
    1 3 2 3 4
    
首页