## DMOPC '15 Contest 5 P6 - Event Horizon

View as PDF

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Using his experiences with time travel, as well as some knowledge of general relativity and black holes, the mad scientist Kyouma has created a doomsday device. He plans to cause a localized event horizon: given a series of events and connections, sever the events so that no event can be affected by another.

Kyouma has spotted a network of events which he will use his device on. This network can be treated as an undirected graph with vertices (numbered from to ) and edges, with each vertex representing an event to disconnect and each edge representing a connection between two events. When Kyouma triggers his device, a large distortion in spacetime is created, allowing him to remove any group of edges from the graph which forms a pseudoforest. He considers the network destroyed and his task complete once he has removed all edges through uses of his doomsday device.

However, some of the connections between events are abnormally strong: that is, it is possible for multiple edges to exist between the same pair of vertices, all of which must be removed. It is guaranteed that each edge connects two distinct vertices.

Kyouma, while an evil genius, is neither very rich nor very patient. Therefore, he would like to know the fewest number of times he must activate his device to destroy the network.

#### Note

A pseudoforest is a series of edges where, for each connected component, there is at most one simple cycle. Since there may be repeated edges in this graph, a simple cycle contained in a valid pseudoforest may consist of two vertices connected by two edges.

#### Constraints

##### Subtask 2 [90%]

For all tasks, the constraints , and will hold.

#### Input Specification

On the first line will be two space separated integers: , the number of vertices, and , the number of edges.

On each of the next lines there will be two integers and , indicating a two-way connection between and .

#### Output Specification

Print a single integer, the fewest number of pseudoforests that must be removed in order to disconnect all vertices.

#### Sample Input 1

3 2
1 2
3 2

#### Sample Output 1

1

#### Sample Input 2

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

#### Sample Output 2

2

#### Explanation for Sample 2

There is no way to remove all the edges with one pseudoforest. To remove it with two, Kyouma could for example remove the edges and at first, and then remove the remaining edges afterwards.

#### Sample Output 3

2 2
1 2
1 2

#### Sample Output 3

1

#### Explanation for Sample 3

As can be seen, a cycle between two nodes ( and in this case) is considered a valid cycle, and can therefore be removed in one activation.

#### Sample Input 4

3 4
1 2
2 1
2 3
3 2

#### Sample Output 4

2

• commented on Feb. 9, 2016, 7:05 p.m. edit 5
6 9
1 2
1 3
2 3
2 4
3 4
3 5
4 5
4 6
5 6
• commented on Feb. 9, 2016, 7:38 p.m.

I can only say that the answer to that case (assuming that line breaks are inserted and spaces deleted where necessary) exists and is unambiguous. Is there any particular clarification that would be answered by that case?

• commented on Feb. 9, 2016, 7:45 p.m.

Yeah I'm not exactly understanding how Kyouma "removes" pseudoforests. Can you explain how he would do it here for the best result?

• commented on Feb. 9, 2016, 7:56 p.m. edited

He removes a subset of edges from the graph. From your example, he could remove the edges (1,2), (2,3) and (1,3) at once with one use of the machine, because those edges form a valid pseudoforest. Each edge must be removed at some point in time. (This does not necessarily lead to a correct answer, it is just an example.)