#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:
- The graph is connected.
- All nodes are partitioned into infinitely many layers: layer , layer , layer , , with nodes in each layer. For convenience, we denote the -th node in layer by .
- Edges are allowed between nodes within the same layer, and between nodes in adjacent layers. No other edges are allowed.
- If there is an edge of weight between and , then for any positive integer , there is also an edge between and with weight , where is any positive integer.
- If there is an edge of weight between and , then for any positive integer , there is also an edge between and with weight , where 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 .
Input Format
The input file infinite.in contains three space-separated non-negative integers on the first line: , , and .
From line to line , each line contains three positive integers , , and , indicating that there is an edge of weight between and .
From line to line , each line contains three positive integers , , and , indicating that there is an edge of weight between and . Each line’s three integers are separated by a single space.
There may be more than one edge between nodes and . 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 | | | | | 1 | | | | | 2 | | | | | 3 | | | | | 4~7 | | | | | 8~10 | | | |
In 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号