P26614 [AtCoder] Hashipon
提高+
题目描述

Problem Description

In a connected graph, an edge whose removal would disconnect the graph is called a bridge.

A simple graph is a graph that does not contain self-loops or multiple edges.

Watanabe-kun named a simple graph containing exactly one bridge a Hashipon graph.

Given a connected undirected simple graph, determine the minimum number of edges that need to be added to make it a Hashipon graph. If it is impossible to make it a Hashipon graph, output IMPOSSIBLE.

Input Format

The input is given from the standard input in the following format:

$ V $ $ E $ $ a_1 $ $ b_1 $ $ a_2 $ $ b_2 $ : $ a_E $ $ b_E $

  • The first line contains the number of vertices $ V $ ( $1\ \leq\ V\ \leq\ 100,000$ ) and the number of edges $ E $ ( $0\ \leq\ E\ \leq\ 150,000$ ) separated by a space.
  • The following $ E $ lines contain the indices of the vertices connected by the $ i $ -th edge $ a_i $ and $ b_i $ ( $0\ \leq{}\ a_i,\ b_i\ \leq{}\ V-1$ ) separated by a space.
  • It is guaranteed that the given graph is a connected undirected simple graph.

Output Format

Output the minimum number of edges to be added, or IMPOSSIBLE in one line. Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

4 4
0 1
1 2
2 3
3 1

Sample Output #1

0

Sample Input #2

5 5
0 1
1 2
2 3
3 1
3 4

Sample Output #2

1

Sample Input #3

3 2
0 1
1 2

Sample Output #3

IMPOSSIBLE

Sample Input #4

1 0

Sample Output #4

IMPOSSIBLE

Notes/Hints

Scoring

This problem has partial scoring.

  • If you correctly solve all test cases where $V\ \leq\ 20$, you will be awarded $ 35 $ points.
  • If you correctly solve all test cases where $V\ \leq\ 2000$, you will be awarded $ 30 $ points.
  • If you correctly solve all test cases, you will be awarded an additional $ 55 $ points.

Sample Explanation 1

The given graph is already a Hashipon graph.

Sample Explanation 2

For example, adding an edge connecting vertex 1 and vertex 4 can make the graph a Hashipon graph.

Sample Explanation 3

A Hashipon graph must be a simple graph.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 4 0 1 1 2 2 3 3 1
样例输出
0