Drifting
시간 제한2초메모리 제한1024 MB
특정 두 번의 이동 조합이 금지된 조건에서 정점 N에 도달할 수 있는지, 도달한다면 지나온 간선 가중치 합의 최솟값을 구한다.
문제
You are given a weighted directed graph of vertices and edges, with vertices numbered to and edges numbered to . The -th () edge connects from vertex to vertex (), and the weight of the edge is .
Also, triplets of integers are given. The -th () triplet is ().
You start at vertex and move to vertex by repeatedly moving along an edge.
In addition, for all (), if you move from vertex to vertex directly, we must next move to a vertex other than vertex .
Judge whether it is possible to reach vertex . If it is possible to reach, also calculate the minimum sum of the weights of the edges you pass through.
입력
출력
If you cannot reach vertex , output . Otherwise, output the minimum sum of the weights of the edges you pass through.
제한
- All inputs consist of integers.
- ()
- ()
- ()
- ()
힌트
In Sample Input 1, the best move is .
In Sample Input 2, the best move is .