#P6165. Critical Rings in a Chain Configuration

    ID: 19385 Type: Default 1000ms 256MiB

Critical Rings in a Chain Configuration

Critical Rings in a Chain Configuration

In Leonardo's "Codex Atlanticus", an early and complex design of a pyramid‐shaped, cloth–covered wooden parachute is described. In a modern test of this design, a series of linked rings (each of which can be opened or closed) is used to attach the cloth. A chain is defined as a sequence of rings linked together such that every ring is connected to at most two neighbors, and the sequence has two distinct endpoints (which are connected to only one neighbor); a single ring is also considered a chain.

A ring is called critical if, when it is opened and removed from the configuration, the remaining rings decompose into a collection of disjoint chains (or possibly no rings at all). Note that the original configuration may contain rings connected to three or more neighbors. After removal of a candidate ring, each connected component in the remaining configuration must form a chain. In other words, if a connected component has at least two rings then:

  • The component must be a tree (i.e. acyclic, with exactly n - 1 edges for n vertices in that component), and
  • The degree (i.e. number of neighbors within the component) of every ring is at most 2.

For example, consider a configuration of 7 rings numbered 0 to 6. Removing ring 2 results in three chains: [1] (an isolated ring), [0,5,3,4] (a single chain) and [6] (an isolated ring). Similarly, removing ring 3 yields chains [1,2,0,5], [4] and [6]. No other ring removal produces a decomposition into disjoint chains. Your task is to compute the number of critical rings in the given configuration.

Note on chains: A chain (or path) is a connected acyclic graph with the maximum degree ≤ 2. A single vertex is regarded as a chain by definition.

inputFormat

The first line of input contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of rings and m is the number of connections. The rings are numbered from 0 to n−1. Each of the following m lines contains two integers u and v (0 ≤ u, v < n, u ≠ v) indicating that ring u is connected to ring v (the connections are bidirectional). It is guaranteed that there is at most one connection between any pair of rings.

outputFormat

Output a single integer—the number of critical rings in the configuration.

sample

1 0
1

</p>