Under construction

Still being built. Things may change

Two Paths

Time limit5sMemory limit1024 MB

Summary
Given a DAG, find edge-disjoint simple paths from A to B and from C to D with the minimum total length, or report NO.
Level

Medium7 of 10

Topics
Graph, Shortest path, Topological sort
Solved
No attempts yet

Statement

You are given a directed acyclic graph with two fixed pairs of vertices: (A,B)(A, B) and (C,D)(C, D). Consider all pairs of edge-disjoint simple paths, one from AA to BB and another from CC to DD. Find the pair with minimal total length.

Input

The first line contains two integers nn and mm: the number of vertices and edges in the graph (1≤n≤50001 \le n \le 5000, 0≤m≤20 0000 \le m \le 20\,000). Each of the next mm lines contains two integers uu and vv, meaning there is an edge from uu to vv (1≤u,v≤n1 \le u, v \le n). The graph has no loops, no multiple edges, and no cycles. The last line contains the fixed vertices in the order AA, BB, CC, DD (1≤A,B,C,D≤n1 \le A, B, C, D \le n).

Output

If no pair of paths exists, print a single line with the word NO. Otherwise, print YES on the first line, then the path from AA to BB, then the path from CC to DD. Each path takes two lines: the number of vertices in the path, then the vertices in the order they are visited. Each path must be simple, so no vertex appears more than once in the same path. If several solutions exist, print any of them.

Examples2

  1. Example 1

    Input
    4 3
    1 2
    2 3
    3 4
    1 2 3 4
    
    Expected output
    YES
    2
    1 2
    2
    3 4
    
  2. Example 2

    Input
    4 3
    1 2
    2 3
    3 4
    1 3 2 4
    
    Expected output
    NO