[BOJ 6773] The Hungary Games

View as PDF

Submit solution

Points: 4
Time limit: 2.0s
Memory limit: 512M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

Welcome to the Hungary Games! The streets of Budapest form a twisted network of one-way streets. You have been forced to join a race as part of a “Reality TV” show where you race through these streets, starting at the Szechenyi thermal bath ( s for short) and ending at the Tomb of Gul¨ Baba (t for short).</p>

Naturally, you want to complete the race as quickly as possible, because you will get more promotional contracts the better you perform. However, there is a catch: any person who is smart enough to take a shortest s-t route will be thrown into the Pálvölgyi cave system and kept as a national treasure. You would like to avoid this fate, but still be as fast as possible. Write a program that computes a strictly-second-shortest s-t route.

Sometimes the strictly-second-shortest route visits some nodes more than once; see Sample Input 2 for an example.

입력 형식

The first line will have the format N M, where N is the number of nodes in Budapest and M is the number of edges. The nodes are 1, 2, . . . , N; node 1 represents s; node N represents t. Then there are M lines of the form A B L, indicating a one-way street from A to B of length L. You can assume that A ≠ B on these lines, and that the ordered pairs (A, B) are distinct.

출력 형식

Output the length of a strictly-second-shortest route from s to t. If there are less than two possible lengths for routes from s to t, output −1.

예제 입력 1

4 6
1 2 5
1 3 5
2 3 1
2 4 5
3 4 5
1 4 13

예제 출력 1

11

예제 입력 2

2 2
1 2 1
2 1 1

예제 출력 2

3

Comments

There are no comments at the moment.