#P3351. [ZJOI2016] 电阻网络
[ZJOI2016] 电阻网络
Description
Xiao Y is a very smart girl, but she can only compute the resistance between two nodes using series and parallel reductions. Now, given a resistor network, she wants to know how many pairs of vertices () have their resistance computable by series-parallel methods.
We formalize when the resistance between a pair () can be computed using series-parallel methods. First, regard the resistor network as a graph with vertices and edges (each resistor corresponds to an edge).
Let be the union of the vertices on all simple paths (paths that do not visit a vertex more than once) from to . In other words, for a vertex , if there exists a simple path from to that passes through , then .
If is nonempty and the induced subgraph of is a two-terminal series-parallel graph with terminals and , then the resistance between and can be computed using series-parallel methods.
A graph with two distinct terminals is called a two-terminal graph, where one is the source and the other is the sink. The parallel composition of two two-terminal graphs builds a new graph by identifying their sources and their sinks, respectively. The series composition of two two-terminal graphs builds a new graph by identifying the sink of with the source of . A graph formed from several two-terminal graphs consisting of two vertices and one edge, by a sequence of series and parallel compositions, is called a two-terminal series-parallel graph.

The induced subgraph of the set has vertex set , and its edge set consists of edges in the original graph whose both endpoints lie in .
Input Format
The first line contains two positive integers , the number of nodes and the number of resistors in the network.
Each of the next lines contains two positive integers (, ), indicating there is a resistor between nodes and .
Output Format
Output a single line containing the answer: the number of vertex pairs whose resistance can be computed using series-parallel methods.
6 6
1 2
1 3
1 4
2 3
2 4
5 6
6
Hint
【Sample Explanation #1】
The feasible pairs are , , , , , .
【Constraints】
For 10% of the testdata, , the original graph is connected and has no articulation point.
For another 10% of the testdata, , the original graph is connected and has no articulation point.
For 30% of the testdata, .
For 40% of the testdata, .
For another 30% of the testdata, the original graph is connected and has no articulation point.
For 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号