#P1793. Critical Intersections Detection
Critical Intersections Detection
Critical Intersections Detection
You are given an undirected graph representing a network of farms and intersections. The nodes are numbered from \(1\) to \(n\). Farm \(A\) is represented by node \(1\), farm \(B\) by node \(n\), and the intersections in between by nodes \(2,3,\ldots,n-1\). There are \(m\) edges in the graph. Each edge connects two different nodes.
A mandatory intersection is an intersection (i.e. a node with value between \(2\) and \(n-1\)) that lies on every possible path from node \(1\) (farm \(A\)) to node \(n\) (farm \(B\)). In other words, if the intersection is removed, there will be no path from \(1\) to \(n\).
Your task is to find all such mandatory intersections. If there is no mandatory intersection, output -1
.
Note: The graph is undirected and may contain multiple paths between nodes.
inputFormat
The first line contains two integers \(n\) and \(m\) \((2 \le n \le 10^5,\; 1 \le m \le 10^5)\) representing the number of nodes and edges in the graph, respectively.
Each of the next \(m\) lines contains two integers \(u\) and \(v\) \((1 \le u, v \le n, u \neq v)\), indicating that there is an undirected edge between nodes \(u\) and \(v\).
outputFormat
Print the mandatory intersections (i.e. those nodes from \(2\) to \(n-1\) that lie on every path from node \(1\) to node \(n\)) in increasing order, separated by a space. If there is no mandatory intersection, print -1
.
sample
4 4
1 2
2 4
1 3
3 4
-1