[Solution] Optimal Graph Partition for Fast Routing 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 connectedThe set
of free edges of the partition are those edges that are not part of the merged nodes, that is, those edges that connect the merged nodes. is the weight of the edge .
In this subtask, it is necessary to solve a narrowed bi-criteria optimization problem:The score for SubTask1 for the
graph is calculated by the 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.
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-gp1-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