Clique Graph Shortest Path Sum
Time limit2sMemory limit512 MB
A graph is given as a union of K cliques on overlapping vertex lists; sum the shortest path lengths over all vertex pairs.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Shortest path
- Solved
- No attempts yet
Problem
An undirected, unweighted, connected graph has vertices numbered 0 through .
The edges of are fixed by two arrays, and . holds vertex numbers, and the same number may appear in it more than once. holds the lengths of the blocks that is cut into, starting from the front.
Define as the sum of the first elements of . For example, if , then , , and .
For every with , take every pair that satisfies . Each such pair gives one edge between vertex and vertex . In other words, the vertices through form a complete graph. has no other edges.
Given , and , write a program that computes the shortest path length for every pair of two distinct vertices and prints the sum. The graph given in the input is always connected.
Input
The first line contains the number of vertices (), the size of () and the size of (), separated by spaces.
The second line contains the elements of in order. The third line contains the elements of in order.
Every element of is between 0 and . Every element of is an integer between 2 and , and their sum is at most . For every with , the values are distinct.
Output
Print on the first line the sum of the shortest path lengths over all pairs of two distinct vertices. Each pair is counted once. The value can exceed the range of a 32-bit integer.