2305. Pirates’ Path

单点时限: 5.0 sec

内存限制: 256 MB

Our captain Jack Sparrow is again on the natives’ island where again the natives think he is a God. But Captain Jack ain’t giving in easily (especially when his life is at stake) and is trying to escape. The island is divided into different areas separated from one another by the many rivers abundant on the island. Two areas are adjacent if they are connected through a bridge. Of course captain Jack has to make it from the area where he’s been kept in captivity to the area where the Black Pearl, his dear ship, is located. Quite unfortunately, the natives are very eager to keep their “God” on the island so they have decided that they will guard some selection of the bridges by putting one man on each selected bridge. Now, our captain, being as unwilling as he is to spend any extra effort whatsoever on a job (as well as desirous of being merciful to his devotees), would like to incapacitate as few natives as possible on his way back. WARNING: Jack needs to make his decision QUICKLY!

输入格式

Input consists of $b + 1$ lines where $b$ is the number of bridges on the island. The first line contains $4$ numbers separated by a single space:

$n \ b \ s \ e$

$n$ is the number of areas on the island, $b$ is the number of bridges, $s$ (where $0 \le s < n$) is the area where Captain Jack is being held and $e$ (where $0 \le e < n$) is the area where the Black Pearl is located. Each of the next $b$ lines describes a bridge. The line will contain $3$ numbers separated by a single space:

$a \ b \ c$

$a$ and $b$, $0 \le a, b < n$ are the areas connected by the bridge described by the line and $c$ is a bit, either $0$ or $1$, indicating whether the bridge is being guarded by a man or not. If it is being guarded, only one man will be a guard.

$0 \le n \le 100000,0 \le b \le 1000000$

输出格式

Note that there may not be a path from the area where Captain Jack is being kept to the area of the Black Pearl. If this is the case, output should be a single line containing the following (quotes for clarity):

It’s over with Captain Jack. At least till Pirates of the Caribbean 3.

In case there is a path to the Black Pearl, output should be a single line containing (quotes for clarity):

x native(s) on the easiest way for Captain Jack.

where $x$ should be replaced by the least number of natives guarding bridges on a path from the starting area to the area of the Black Pearl.

样例

Input
6 5 1 5
0 1 0
0 2 0
1 2 0
1 3 1
3 4 0
Output
It’s over with Captain Jack. At least till Pirates of the Caribbean 3.
Input
7 11 0 6
0 1 0
0 2 1
1 2 0
1 3 1
2 4 0
1 5 1
3 5 0
3 4 1
3 6 0
4 5 1
5 6 1
Output
1 native(s) on the easiest way for Captain Jack.

18 人解决,32 人已尝试。

32 份提交通过,共有 212 份提交。

6.1 EMB 奖励。

创建: 15 年,8 月前.

修改: 6 年,3 月前.

最后提交: 2 年,11 月前.

来源: 2007 Maryland High-school Programming Contest

题目标签