[Solution] Optimal Graph Partition for Fast Routing (GP2) Codeforces Solution
In computer networks, the Internet Protocol (IP) uses path routing. With path routing, the packet contains only the destination address; routers decide which "next hop" to forward each packet on to get it closer to its destination. Each router makes this decision locally, based only on the destination address and its local configuration. One way to store this configuration is to use routing tables, which means for each router, we store the "next hop" for every possible destination. However, as the scale of the network grows larger, the size of the router table grows as well. It is a big issue since routers only have limited computing resources. One way to address this issue is to divide the graph into several partitions.
We can further merge into a single node . Then for , we need to store only entries in its routing table. For routers in or , it only needs to store entries. Your task is to find an optimal partition of the initial graph to minimize the maximum size of the routing table for all routers in the network.
A computer network under consideration is an undirected connected graph , where , , ,
A partition of the network is a set of non-empty subsets of such that every node belongs to exactly one of these subsets, and the induced sub-graph for each subset in is connected. Here, one subset corresponds to one abstract node mentioned above.
Formally, is a valid partition if and only if is a family of sets that satisfies:
- , the induced subgraph is connected
The routing table size of any node for the corresponding partition is defined by the following equation:
The "next hop" is defined by the shortest path tree. For each node pair , the "next hop" is a node , such that there is an edge connected from to directly, and , here denotes the length of the shortest path from to , and denotes the weight of the edge connecting and . The valid "next hop" may not be unique. After the graph partitioning, the "next hop" for nodes in the same subset is calculated via the shortest path in the induced sub-graph using the same method above. We compute the "next hop" for two nodes from different subsets of by calculating the shortest path in the "compressed" graph (we compress all nodes in the same subset into a single node). The new graph only contains edges between nodes from different subsets. And then find the shortest path from the subset containing to the subset containing . Suppose the first edge in this path is between . From the definition, , are in different subsets of , and is in the same subset of . If , then the "next hop" of is , otherwise the "next hop" of is the "next hop" of .
The path from to may differ from the path in the graph before partition.
For example:
Originally, the packet transmission path from to is the shortest in the whole graph, so it is , and the total length is 3.
If our partition , then the packet transmission path from to is the shortest path in the subgraph, so it is . The total length is , which gets much greater after partition.
Define as the length of the shortest path from to in graph .
Let be the length of the optimal transmission path after dividing graph by partition . The way to determine is specified later.
For node , we define , where is the unique subset in such that .
Define two new edge sets:
, .
In other words, is almost a copy of the original graph, except for all edges that have both endpoints in the same subset of (their weights are set to ). is also almost a copy of the original graph, except for all edges that connect different subsets of (their weights are set to infinity).
Let be the length of the shortest path from to in .
Let be the length of the shortest path from to in .
For nodes , we define that be the edge with the samllest edge index which makes the following equation holds:
We can prove such an edge always exists.
Then can be calculated recursively:
- For nodes , .
- For nodes , let , then .
The score for SubTask2 for the graph is calculated by the formula:
The final score for SubTask2 is calculated according to the following formula:
Input
The first line contains two integers and — the number of nodes and edges, respectively.
Each of the next lines contains three integers and (), denoting an edge between the node and with weight . is the edge with index in the edge set . It is guaranteed that the input graph is connected and there are no multiple edges. That is, any pair (in any order) of nodes appear in this list no more than once.
The next line contains two numbers: one integer (), the size of node set and one real number , given with at most six digits after the decimal point .
Each of the next lines contains one integer (), the node in .
In the first line, output the number of subsets in your partition .
The -th line should begin with a single number — the size of the -th subset, followed by numbers, denoting the node IDs in the -th subset.
During the coding phase, your solutions are tested against pre-tests only. The first of them are open and available for download at the link problem-gp2-open-testset.zip in the "contest materials" section in a sidebar.
After the end of the coding phase, the last submission that scored a positive number of points on the pre-tests will be selected. It will be retested in the final tests. The rest of your submissions will be ignored. The final tests are secret and not available to the participants, they are mostly realistic. The result obtained on the final tests is your final official result for this problem.
- According to the formula, the solution with a larger score wins.
- If two solutions have the same score, the solution submitted first wins.
No comments:
Post a Comment