GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday, 28 September 2022

[Solution] Optimal Graph Partition for Fast Routing Codeforces Solution



GP1. Optimal Graph Partition for Fast Routing (GP1)
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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.

For example, in the above figure, there are 12 routers in the network. Each edge has a certain weight. Each router has to store 12 table entries for all possible destinations in the network (including itself). We can merge four nodes in the graph into one large abstract node R2. When routers are merged, all existing edges connected to the elements of a large node are preserved. Then all routers outside R2 only need to store 9 table entries. Therefore, in this case, we can assign the same "next hop" for all destination routers in R2. The intuition behind this is that router R1 does not need to care how to get R24 from R21 if R1 wants to send a packet to R24R1 just needs to find a path to get its packet to an arbitrary router inside R2 and then let the routers inside R2 decide how to get R24. For routers inside R2, however, there are still 12 table entries, because they need to know the routes to each other.

We can further merge R31,R32,R33,R34 into a single node R3. Then for R1, we need to store only 6 entries in its routing table. For routers in R3 or R2, it only needs to store 9 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 G=(V,E), where |V|=N (2N105)|E|=M (1M2×105)V={0,1,,N1}E={e=(u,v,w)

There is an edge between nodes u and v with weight w}.

A partition P of the network G is a set of non-empty subsets of V such that every node vV belongs to exactly one of these subsets, and the induced sub-graph for each subset in P is connected. Here, one subset corresponds to one abstract node mentioned above.

Formally, P is a valid partition if and only if P is a family of sets that satisfies:

  • P
  • APA=V
  • A,BP:ABAB=
  • AP, the induced subgraph G[A] is connectedThe set 

FE(P) of free edges of the partition P are those edges that are not part of the merged nodes, that is, those edges that connect the merged nodes. w(e) is the weight of the edge e.

In this subtask, it is necessary to solve a narrowed bi-criteria optimization problem:The score for SubTask1 for the 

ith graph is calculated by the formula:

Input

The first line contains two integers N and M (2N105;N1M2×105) — the number of nodes and edges, respectively.

Each of the next M lines contains three integers ui,vi and wi (0ui, viN1, uivi, 1wi105), denoting an edge between the node ui and vi with weight wiei=(ui,vi,wi) is the edge with index i in the edge set E. 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.

Output

In the first line, output the number of subsets in your partition P.

The (i+1)-th line should begin with a single number cnti — the size of the i-th subset, followed by cnti numbers, denoting the node IDs in the i-th subset.

Scoring

During the coding phase, your solutions are tested against pre-tests only. The first 5 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.

  1. According to the formula, the solution with a larger score wins.
  2. If two solutions have the same score, the solution submitted first wins.

No comments:

Post a Comment