PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000088. Đường bị phong tỏa (Road Blocked)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường bị phong tỏa (Road Blocked)
Road Blocked
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected weighted graph has individually numbered roads. Process operations 1 i (close currently open road ) and 2 x y (report shortest distance using only open roads, or -1). Each road is closed at most once.
Input
First ; then undirected roads qx<y$ for queries).
Output
For each type-2 query print the current shortest distance or -1, one per line.
Subtasks
-
Subtask 1 (40 points): . , ; mỗi cạnh chỉ bị xóa tối đa một lần.
-
Subtask 2 (60 points): . , ; mỗi cạnh chỉ bị xóa tối đa một lần.
Examples
Input
3 3 5
1 2 5
1 3 10
2 3 6
2 1 3
1 2
2 1 3
1 1
2 1 3
Output
10
11
-1
Explanation
Initially d(1,3)=10. Closing road 2 forces the 1–2–3 route of length 11. Closing road 1 then makes the destination unreachable.