Weird full graph solution codechef 2021
SOLUTION
” CLICK HERE “
You are given a weighted directed graph of
vertices and edges, and an array of length . Initially, every ordered pair of vertices is connected by a directed edge of cost (this also includes self-loops).
Then there were changes in edges' weights such that the weight of the directed edge is now equal to . You are asked to find the sum of the lengths of the shortest paths over all ordered pairs of distinct vertices.
Input Weird full graph solution codechef 2021
- The first line contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
- The third line of each test case contains a single integer .
- The next lines contain information about the changed edges in the format.
Output Weird full graph solution codechef 2021
For each test case, output the sum of the lengths of the shortest paths over all ordered pairs of vertices.
Constraints Weird full graph solution codechef 2021
- The sum of over all tests does not exceed .
- The sum of over all tests does not exceed .
- It is guaranteed that the weight of the edge was changed at most once.
Subtasks Weird full graph solution codechef 2021
Subtask #1 (8 points, time limit 1 second): The sum for all tests does not exceed .
Subtask #2 (22 points, time limit 1 second): Each vertex belongs to at most one changed edge (in other words, the edges do not overlap).
Subtask #3 (30 points, time limit 1 second): The sum for all tests does not exceed .
Subtask #4 (40 points, time limit 4.5 seconds): original constraints.
Sample Input
3
3
2 4 1
0
4
1 2 3 4
2
1 2 1
3 4 2
5
2 6 5 1 7
5
1 3 4
2 4 3
3 5 4
4 1 2
5 2 3
Sample Output
14
29
72
Explanation Weird full graph solution codechef 2021
Example case 1: The lengths of the shortest paths between vertices and are and the answer is .
Example case 2: The lengths of the shortest paths between the vertices and are equal to except for the pair of vertices for which the distance is .
Social Plugin