306807: CF1253F. Cheap Robot
Memory Limit:512 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Cheap Robot
题意翻译
给你一张 $N$ 个点的带权无向连通图,其中结点 $1,2,…,k$ 为充电中心。 一个机器人在图中行走,假设机器人的电池容量为 $c$,则任何时刻,机器人的电量 $x$ 都必须满足 $0\le x\le c$。如果机器人沿着一条边权为 $w$ 的边从结点 $i$ 走到结点 $j$,它的电量会减少 $w$。机器人可以在到达某个充电中心时把电量充满。 现在有 $q$ 个询问,每次询问机器人要从 $a$ 点到达 $b$ 点,电池容量至少为多少,各个询问相互独立。保证 $a$ 点和 $b$ 点都是充电中心。 translated by vectorwyx题目描述
You're given a simple, undirected, connected, weighted graph with $ n $ nodes and $ m $ edges. Nodes are numbered from $ 1 $ to $ n $ . There are exactly $ k $ centrals (recharge points), which are nodes $ 1, 2, \ldots, k $ . We consider a robot moving into this graph, with a battery of capacity $ c $ , not fixed by the constructor yet. At any time, the battery contains an integer amount $ x $ of energy between $ 0 $ and $ c $ inclusive. Traversing an edge of weight $ w_i $ is possible only if $ x \ge w_i $ , and costs $ w_i $ energy points ( $ x := x - w_i $ ). Moreover, when the robot reaches a central, its battery is entirely recharged ( $ x := c $ ). You're given $ q $ independent missions, the $ i $ -th mission requires to move the robot from central $ a_i $ to central $ b_i $ . For each mission, you should tell the minimum capacity required to acheive it.输入输出格式
输入格式
The first line contains four integers $ n $ , $ m $ , $ k $ and $ q $ ( $ 2 \le k \le n \le 10^5 $ and $ 1 \le m, q \le 3 \cdot 10^5 $ ). The $ i $ -th of the next $ m $ lines contains three integers $ u_i $ , $ v_i $ and $ w_i $ ( $ 1 \le u_i, v_i \le n $ , $ u_i \neq v_i $ , $ 1 \le w_i \le 10^9 $ ), that mean that there's an edge between nodes $ u $ and $ v $ , with a weight $ w_i $ . It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes) and connected. The $ i $ -th of the next $ q $ lines contains two integers $ a_i $ and $ b_i $ ( $ 1 \le a_i, b_i \le k $ , $ a_i \neq b_i $ ).
输出格式
You have to output $ q $ lines, where the $ i $ -th line contains a single integer : the minimum capacity required to acheive the $ i $ -th mission.
输入输出样例
输入样例 #1
10 9 3 1
10 9 11
9 2 37
2 4 4
4 1 8
1 5 2
5 7 3
7 3 2
3 8 4
8 6 13
2 3
输出样例 #1
12
输入样例 #2
9 11 3 2
1 3 99
1 4 5
4 5 3
5 6 3
6 4 11
6 7 21
7 2 6
7 8 4
8 9 3
9 2 57
9 3 2
3 1
2 3
输出样例 #2
38
15