#FW0000113. Số cách đóng chi nhánh hợp lệ (Number of Possible Sets of Closing Branches)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số cách đóng chi nhánh hợp lệ (Number of Possible Sets of Closing Branches)
Number of Possible Sets of Closing Branches
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected weighted graph has branches indexed from to , with possible parallel roads. Choose any subset of branches to close. All closed branches, including roads incident to them, become unusable. A closing set is valid if every two remaining open branches have shortest-path distance at most in the induced graph of open branches. Zero or one open branch is always valid. Count all valid closing sets.
Input
First line: . Then undirected weighted edges . Vertices are -indexed.
Output
Print the number of valid closing sets.
Subtasks
-
Subtask 1 (40 points): , , , . All input conditions remain in force.
-
Subtask 2 (60 points): , , , . All input conditions remain in force.
Examples
Input
3 2 3
0 1 2
1 2 2
0 2 10
Output
6
Explanation
There are 4 valid open sets of size at most 1, plus the valid open pairs {0,1} and {1,2}; total 6.