#P4499. [CTSC2011] 无穷图的桥

[CTSC2011] 无穷图的桥

Description

The goal is to find all bridges in an undirected graph with infinitely many nodes.

This undirected graph has the following properties:

  1. The graph is connected.
  2. All nodes are partitioned into infinitely many layers: layer 11, layer 22, layer 33, \cdots, with nn nodes in each layer. For convenience, we denote the xx-th node in layer ii by (i,x)(i, x).
  3. Edges are allowed between nodes within the same layer, and between nodes in adjacent layers. No other edges are allowed.
  4. If there is an edge of weight dd between (i,x)(i, x) and (i,y)(i, y), then for any positive integer jj, there is also an edge between (j,x)(j, x) and (j,y)(j, y) with weight 0.9jid0.9^{j-i} d, where jj is any positive integer.
  5. If there is an edge of weight dd between (i,x)(i, x) and (i+1,y)(i + 1, y), then for any positive integer jj, there is also an edge between (j,x)(j, x) and (j+1,y)(j + 1, y) with weight 0.9jid0.9^{j-i} d, where jj is any positive integer. The undirected graph shown below satisfies all the properties above.

An undirected graph with infinitely many nodes is connected if and only if there exists a path between any pair of nodes in the graph. An edge is a bridge if and only if removing it makes the entire graph disconnected.

Please write a program to read this connected infinite graph and compute the sum of weights of all its bridges. For example, in the figure above, the bold edge is the unique bridge, so the sum of weights of bridges is 11.

Input Format

The input file infinite.in contains three space-separated non-negative integers on the first line: nn, m1m_1, and m2m_2.
From line 22 to line m1+1m_1 + 1, each line contains three positive integers xx, yy, and dd, indicating that there is an edge of weight dd between (1,x)(1, x) and (1,y)(1, y).

From line m1+2m_1 + 2 to line m1+m2+1m_1 + m_2 + 1, each line contains three positive integers xx, yy, and dd, indicating that there is an edge of weight dd between (1,x)(1, x) and (2,y)(2, y). Each line’s three integers are separated by a single space.

There may be more than one edge between nodes xx and yy. Self-loops are allowed.

Output Format

The output file infinite.out contains exactly one line with a real number: the sum of weights of all bridges, rounded to two decimal places.

3 1 3
1 2 4
1 2 5
2 3 3
3 3 1
1.00
1 1 1
1 1 100
1 1 1
10.00

Hint

[Sample Explanation 1]
This is the same as the example given in the problem statement.

Constraints ||||| | :----------- | :----------- | :----------- | :----------- | | Data ID | nn | m1m_1 | m2m_2 | | 1 | 10\leq 10 | 50\leq 50 | 50\leq 50 | | 2 | 10000\leq 10000 | 40000\leq 40000 | 40000\leq 40000 | | 3 | 300000\leq 300000 | 500000\leq 500000 | =1=1 | | 4~7 | 300000\leq 300000 | 500000\leq 500000 | 500\leq 500 | | 8~10 | 300000\leq 300000 | 500000\leq 500000 | 500000\leq 500000 |

In 100% of the testdata, d100d \leq 100.

Translated by ChatGPT 5