#P8604. Danger Factor in a Network

    ID: 21770 Type: Default 1000ms 256MiB

Danger Factor in a Network

Danger Factor in a Network

Given an undirected network connecting multiple stations, some stations are linked by channels. However, the network has its vulnerabilities: when an enemy destroys a station, its removal may disconnect some pairs of the remaining stations.

For any two distinct stations \(x\) and \(y\), we define the danger factor \(DF(x, y)\) as the number of critical stations among the remaining ones. A station \(z\) (with \(z \neq x,y\)) is called a critical station for \(x\) and \(y\) if, after \(z\) is removed (along with all its incident edges), there is no path connecting \(x\) and \(y\). In other words, \(DF(x, y)\) is the count of such stations \(z\) for the given pair \(x\) and \(y\).

Your task is, given the network structure and a query consisting of two stations \(x\) and \(y\), to compute \(DF(x, y)\).

inputFormat

The first line contains two integers \(n\) and \(m\) indicating the number of stations and the number of channels respectively. The stations are numbered from 1 to \(n\).

Each of the following \(m\) lines contains two integers \(u\) and \(v\) which represent an undirected channel connecting station \(u\) and station \(v\).

The last line contains two distinct integers \(x\) and \(y\), representing the two stations between which you need to calculate the danger factor \(DF(x,y)\).

outputFormat

Output a single integer, the danger factor \(DF(x,y)\), i.e. the total number of stations \(z\) (with \(z\neq x,y\)) whose removal disconnects \(x\) and \(y\).

sample

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