Lexicopolis
시간 제한2초메모리 제한1024 MB
방향 그래프와 매우 큰 k가 주어질 때 s에서 t로 가는 길이 k 경로 중 간선 가중치 기준 사전순 최소 경로를 찾고, 없으면 -1을 출력하며, 있으면 x진법 해시를 1e9+7로 나눈 값을 출력한다.
문제
Welcome to Lexicopolis, the ancient city of legends and treasures. The city is famous for its intricate network of one-way roads. There are intersections and one-way roads connecting the intersections. People can only travel from intersection to intersection along road , and road is associated with a magical number . A path of length from intersection to is a sequence of roads that allows travel from intersection to intersection . A path is lexicographically smaller than another path if at the frst road where they have different magic numbers (not index), the number on the frst path is smaller than the number on the second path.
It is rumored that the tourist who figures out the lexicographically smallest path of length from intersection sto intersection can receive a gift from the Lexicopolis government. Please write a program to fnd the lexicographicall smallest path of length from intersection to . If it is impossible to travel from intersection to with exactly roads, output -1.
입력
The first line contains six integers , , , , , . is the number of intersections. is the number of roads. is the starting intersection and is the ending intersection. is a number that will be used for outputting the answer. is the length of path. The -th of the following lines contains three integers , and . That means road is from intersection to intersection and associated with magic number .
출력
If there is no path of length from intersection to , output -1. Otherwise, assume such a path exists. Consider the lexicographically smallest path , and output modulo , where is the number provided as the fifth value in the first line of the input.
제한
- for
- for
- for
- for
- for