시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 269 | 80 | 71 | 35.149% |
After last year’s edition of the BAPC, you are still stuck in Delft. In order to participate again this year, you are going to Amsterdam by bus. During the journey you look out of the window and look for traffic signs that point in the direction of Amsterdam. To your surprise, you notice that the bus is never taking the roads that are pointed out by the signs!
You think that the bus company might have chosen a route such that, at no intersection, the bus goes in the direction that is pointed to by the signs. Your friends, however, find this very unbelievable, and don’t think this is possible. Can you figure out whether there exists a bus route that satisfies this requirement? Note that a bus route never visits the same place twice.
A traffic sign pointing in the direction of the shortest route to Amsterdam is placed at every intersection. You may assume that the input graph is both simple and connected, and that there is a unique optimal route to Amsterdam from every intersection.
As output, give one of the following:
4 5 0 2 5 2 1 5 0 3 10 3 1 20 3 2 5
3 0 3 1
4 3 0 1 10 1 2 20 2 3 30
impossible
7 9 0 1 800 6 2 300 2 3 75 3 4 80 4 5 50 4 1 100 1 6 35 0 2 120 0 3 100
2 0 1