PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000086. Giao thông vương quốc AtCoder (AtCoder Kingdom’s Transport)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giao thông vương quốc AtCoder (AtCoder Kingdom’s Transport)
AtCoder Kingdom’s Transport
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A connected undirected positive-weight road network receives new roads, possibly parallel. After each road is built, output the sum of shortest distances over all unordered city pairs .
Input
First , undirected roads , then and new roads $u v w`, all 1-based.
Output
Print totals, one per line.
Subtasks
-
Subtask 1 (40 points): . ; mạng ban đầu liên thông, trọng số dương , không có self-loop.
-
Subtask 2 (60 points): . ; mạng ban đầu liên thông, trọng số dương , không có self-loop.
Examples
Input
3 2
1 2 3
2 3 4
2
1 3 1
1 2 10
Output
8
8
Explanation
Original pairwise distances sum to 14. Adding road 1–3 of length 1 lowers the sum to 8; the subsequent road of length 10 offers no improvement.