#P3351. [ZJOI2016] 电阻网络

    ID: 2400 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划,dp搜索2016各省省选浙江

[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 u,vu, v (uvu \ne v) have their resistance computable by series-parallel methods.

We formalize when the resistance between a pair u,vu, v (uvu \ne v) can be computed using series-parallel methods. First, regard the resistor network as a graph with nn vertices and mm edges (each resistor corresponds to an edge).

Let SS be the union of the vertices on all simple paths (paths that do not visit a vertex more than once) from uu to vv. In other words, for a vertex xx, if there exists a simple path from uu to vv that passes through xx, then xSx \in S.

If SS is nonempty and the induced subgraph of SS is a two-terminal series-parallel graph with terminals uu and vv, then the resistance between uu and vv can be computed using series-parallel methods.

A graph with two distinct terminals s,ts, t 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 X,YX, Y builds a new graph by identifying their sources and their sinks, respectively. The series composition of two two-terminal graphs X,YX, Y builds a new graph by identifying the sink of XX with the source of YY. 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 SS has vertex set SS, and its edge set consists of edges in the original graph whose both endpoints lie in SS.

Input Format

The first line contains two positive integers n,mn, m, the number of nodes and the number of resistors in the network.
Each of the next mm lines contains two positive integers u,vu, v (1u,vn1 \le u, v \le n, uvu \ne v), indicating there is a resistor between nodes uu and vv.

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 (1,2)(1, 2), (1,3)(1, 3), (1,4)(1, 4), (2,3)(2, 3), (2,4)(2, 4), (5,6)(5, 6).

【Constraints】

For 10% of the testdata, n,m10n, m \le 10, the original graph is connected and has no articulation point.
For another 10% of the testdata, n,m100n, m \le 100, the original graph is connected and has no articulation point.
For 30% of the testdata, n,m100n, m \le 100.
For 40% of the testdata, n,m1000n, m \le 1000.
For another 30% of the testdata, the original graph is connected and has no articulation point.
For 100% of the testdata, 1n,m1051 \le n, m \le {10}^5.

Translated by ChatGPT 5