#P11483. Find Safe Points in the Forest

    ID: 13567 Type: Default 1000ms 256MiB

Find Safe Points in the Forest

Find Safe Points in the Forest

You are in a forest represented by an undirected graph with \(n\) nodes and \(m\) edges. The nodes are numbered from \(0\) to \(n-1\) and the edges are bidirectional. In addition, two special nodes are given: the mother cow's position \(s\) and the calf's position \(t\). A simple path from the mother to the calf is defined as a sequence of vertices \(p_0, p_1, \dots, p_k\) satisfying:

  • \(p_0 = s\) (the mother cow's position) and \(p_k = t\) (the calf's position);
  • For every \(0 \le i < k\), there is an edge between \(p_i\) and \(p_{i+1}\);
  • Any edge that is adjacent to node \(3\) is not used more than once in the path. (Note that in a simple path no edge is repeated, so this extra condition is automatically satisfied.)

A vertex is considered dangerous if it appears on at least one simple path from \(s\) to \(t\). Your task is to find all safe points, i.e. all vertices that are not dangerous.

Note: It is possible that some vertices are not even connected to either \(s\) or \(t\), or they lie in a completely separate component. Such vertices are safe.

inputFormat

The input begins with a line containing four integers \(n\), \(m\), \(s\) and \(t\) where \(n\) is the number of vertices and \(m\) is the number of edges. \(s\) and \(t\) are the positions of the mother cow and the calf respectively. It is guaranteed that \(0 \le s, t < n\).

Then follow \(m\) lines, each containing two integers \(u\) and \(v\) (\(0 \le u, v < n\)) indicating that there is an undirected edge between vertices \(u\) and \(v\).

outputFormat

Output all safe vertices in increasing order separated by a space in one line. If every vertex is dangerous, output an empty line.

sample

4 3 0 2
0 1
1 2
2 3
3