C - Bridge Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300300

問題文

自己ループと二重辺を含まない NN 頂点 MM 辺の無向連結グラフが与えられます。
i(1iM)i(1≦i≦M) 番目の辺は頂点 aia_i と頂点 bib_i を結びます。

グラフから辺を取り除いたとき、グラフ全体が非連結になるような辺のことを橋と呼びます。
与えられた MM 本のうち橋である辺の本数を求めてください。

ノート

  • 自己ループ とは、ai=bi(1iM)a_i=b_i(1≦i≦M) であるような辺 ii のことをいいます。
  • 二重辺 とは、ai=aja_i=a_j かつ bi=bj(1i<jM)b_i=b_j(1≦i<j≦M) であるような辺の組 i,ji,j のことをいいます。
  • 無向グラフが 連結 であるとは、グラフの任意の二頂点間に経路が存在することをいいます。

制約

  • 2N502≦N≦50
  • N1Mmin(N(N1)2,50)N-1≦M≦min(N(N−1)⁄2,50)
  • 1ai<biN1≦a_i<b_i≦N
  • 与えられるグラフは自己ループと二重辺を含まない。
  • 与えられるグラフは連結である。

入力

入力は以下の形式で標準入力から与えられる。

NN MM  
a1a_1 b1b_1  
a2a_2 b2b_2
::  
aMa_M bMb_M

出力

MM 本の辺のうち、橋である辺の本数を出力せよ。


入力例 1Copy

Copy
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

出力例 1Copy

Copy
4

与えられるグラフは以下の図で表されます。

570677a9809fd7a5b63bff11e5d9bf79.png

図の赤い辺が橋であり、その数は 44 本です。


入力例 2Copy

Copy
3 3
1 2
1 3
2 3

出力例 2Copy

Copy
0

橋である辺が存在しない場合もあります。


入力例 3Copy

Copy
6 5
1 2
2 3
3 4
4 5
5 6

出力例 3Copy

Copy
5

全ての辺が橋である場合もあります。

Score : 300300 points

Problem Statement

You are given an undirected connected graph with NN vertices and MM edges that does not contain self-loops and double edges.
The ii-th edge (1iM)(1 \leq i \leq M) connects Vertex aia_i and Vertex bib_i.

An edge whose removal disconnects the graph is called a bridge.
Find the number of the edges that are bridges among the MM edges.

Notes

  • A self-loop is an edge ii such that ai=bia_i=b_i (1iM)(1 \leq i \leq M).
  • Double edges are a pair of edges i,ji,j such that ai=aja_i=a_j and bi=bjb_i=b_j (1i<jM)(1 \leq i<j \leq M).
  • An undirected graph is said to be connected when there exists a path between every pair of vertices.

Constraints

  • 2N502 \leq N \leq 50
  • N1Mmin(N(N1)2,50)N-1 \leq M \leq min(N(N−1)⁄2,50)
  • 1ai<biN1 \leq a_i<b_i \leq N
  • The given graph does not contain self-loops and double edges.
  • The given graph is connected.

Input

Input is given from Standard Input in the following format:

NN MM  
a1a_1 b1b_1  
a2a_2 b2b_2
::  
aMa_M bMb_M

Output

Print the number of the edges that are bridges among the MM edges.


Sample Input 1Copy

Copy
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 1Copy

Copy
4

The figure below shows the given graph:

570677a9809fd7a5b63bff11e5d9bf79.png

The edges shown in red are bridges. There are four of them.


Sample Input 2Copy

Copy
3 3
1 2
1 3
2 3

Sample Output 2Copy

Copy
0

It is possible that there is no bridge.


Sample Input 3Copy

Copy
6 5
1 2
2 3
3 4
4 5
5 6

Sample Output 3Copy

Copy
5

It is possible that every edge is a bridge.



2025-04-29 (Tue)
02:55:35 +00:00