Clique Festival
Time limit2sMemory limit512 MB
Given up to 18 weighted cliques added to a graph on n vertices, compute the sum of shortest-path distances over all vertex pairs.
- Level
Hard9 of 10
- Topics
- Graph, Shortest path, Bit manipulation, Dynamic programming
- Solved
- No attempts yet
Problem
John has a graph with vertices labeled with integers . Initially, there are no edges in the graph. Then John modifies the graph times, each time adding a clique to the graph. He chooses an integer and a set which is a non-empty subset of the set of integers . For each unordered pair such that and , John adds an undirected edge between the vertices and with weight . It is possible that parallel edges appear in John's graph.
The distance between vertices and is defined as follows. Denote as the minimum weight of the edge between vertices and , or if there is no such edge. Then . In other words, the distance is the length of the shortest path between and .
Your task is to calculate . It is guaranteed that all summands are finite.
Input
The first line contains two integers and (, ). The next lines contain the descriptions of the added cliques. Each of these lines contains integers (), (), and then integers (, all are distinct). These are the weight of edges in the clique, the number of vertices in the clique, and the labels of these vertices, respectively.
The sum of all in the input does not exceed .
Output
Output a single integer: the answer to the problem.