시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 143 | 58 | 50 | 49.505% |
An evil gang has decided to free prisoners from their prison. The prison is designed as a spiral and has a number of solitary cells. Prisoners are given a certain time to find their way out of prison. They shall be released if they can find their way out within the given time. Otherwise, the prison doors will be closed again. The prison has N cells that are connected together in a spiral form. Each cell has paths with a number of other cells. The prison has E exit doors. While escaping, each cell can contain as many people as possible.
With the assumption that prisoners know every path, write a program that predicts the number of prisoners that can and can't escape from the prison.
The first three input lines contain
The fourth line contains M the number of connections in the prison. Each next M lines, specify a connection (one-way connection) between cells with three integer numbers: two cell numbers A and B (in the range 1, ..., N) and the number of time units it takes to travel from A to B.
Notice that each connection is one-way, i.e., the prisoner can't travel from B to A unless there is another line specifying that passage. Also, the time required to travel in each direction might be different.
Output a single line with the number of prisoners that reached the exit cell.
4 2 1 8 1 2 1 1 3 1 2 1 1 2 4 1 3 1 1 3 4 1 4 2 1 4 3 1
3