QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 2048 MB Total points: 100

#2289. 牢狱或兜风

Statistics

一群青少年在周六晚上偷了一辆跑车去兜风。当地警察局只有一辆警车可以用来当场抓获这些青少年,并将他们送往青少年拘留中心。

这座城市由一系列路口和双向道路组成,每条道路都有一定的长度。青少年会停留在某个路口,直到警车即将到达该路口。在那一刻,青少年想要前往一个距离他们当前位置尽可能远的路口,且不能经过警车所在的道路。他们会迅速查看地图,确定城市中所有在不经过警车所在道路的情况下可以到达的路口。然后,青少年利用卫星导航系统确定到这些路口的距离,并随机选择其中一个距离最远的路口。请注意,卫星导航系统并不知道警车的位置,在计算距离时不会考虑警车。随后,跑车会立即通过任何不经过警车所在道路的路径行驶到该路口,而警察则被甩在后面。青少年会在那里等待,直到警车再次靠近。警察抓获青少年的唯一方法是在他们处于死胡同(只有一个路口连接的路口)时靠近他们。图 J.1 展示了警察如何在第一个样例中抓获青少年。

由于时间对警察来说非常宝贵,他们需要你找出是否有可能以绝对把握抓获这些兜风者。如果可以,假设警察采取最优策略,他们为了保证抓获青少年所需要行驶的最小距离是多少?

输入格式

输入包含:

  • 一行包含四个整数:$n$ ($2 \le n \le 300$),路口的数量;$m$ ($1 \le m \le \frac{n(n-1)}{2}$),道路的数量;$p$ ($1 \le p \le n$),警车的初始位置;以及 $t$ ($1 \le t \le n, t \neq p$),青少年团伙的初始位置。
  • 接下来 $m$ 行,每行包含三个整数 $a, b$ 和 $\ell$ ($1 \le a, b \le n, a \neq b$, 且 $1 \le \ell \le 10^9$),表示路口 $a$ 和 $b$ 之间有一条长度为 $\ell$ 的道路。

每对路口之间最多只有一条道路,且通过这些道路可以从任何路口到达其他任何路口。

输出格式

如果有可能以绝对把握抓获青少年,输出警车需要行驶的最小距离以实现这一目标。否则,输出 “impossible”。

图 J.1:在第一个样例中,警察 (P) 和青少年 (T) 的可能移动方式。警察的移动(实心蓝色箭头)根据边的长度耗费时间,而青少年的移动(虚线红色箭头)是瞬间完成的。

样例

样例输入 1

5 5 1 2
1 2 2
2 3 2
3 4 3
4 5 1
2 5 2

样例输出 1

10

样例输入 2

5 5 1 3
1 2 2
2 3 2
3 4 3
4 5 1
2 5 2

样例输出 2

impossible

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.