Under construction

Still being built. Things may change

Island

Time limit7sMemory limit512 MB

Summary
Count subsets of coastal settlements such that every lake-boundary settlement can reach a chosen one through a planar road network, modulo 10^9+7.
Level

Hard9 of 10

Topics
Graph, Dynamic programming, Union-find
Solved
No attempts yet

Problem

Welcome to the island of Bitcairn! It has everything: settlements, roads, a beautiful lake, the Internet, and a monster living in the lake that is ready to destroy the whole island. A monster in the lake?

Byteasar, governor of Bitcairn, has ordered you to prepare an evacuation plan for tourists in case of a monster attack. He gave you the following information about the island:

  • The island is a ring. Its outer boundary is the boundary of the sea, and its inner boundary is the boundary of the lake.
  • The settlements are numbered consecutively from 11 to nn.
  • Settlements 11 to aa are on the boundary of the lake. They are numbered clockwise or counterclockwise along that boundary.
  • Settlements a+1a+1 to a+ba+b are on the coast (the boundary of the sea). They are numbered clockwise or counterclockwise along the coast.
  • There are mm roads connecting settlements. A road cannot pass through the lake, the sea, or another settlement. Two roads may intersect only at a shared endpoint, so the road network is a planar graph. Each road is either directed or undirected.
  • Every tourist in a settlement on the lake boundary can reach the coast through the road network, possibly using several roads.

To enable evacuation, choose a subset of coastal settlements where seaports will be built. The plan is safe if and only if every tourist in a settlement on the lake boundary can reach at least one settlement on the sea boundary where a seaport is built. Count the safe plans.

Input

The first line contains four integers nn, mm, aa, and bb (2≤n≤500 0002 \le n \le 500\,000, 1≤m≤1 000 0001 \le m \le 1\,000\,000, a,b≥1a, b \ge 1, a+b≤na + b \le n).

Each of the next mm lines describes one road in one of two formats:

  • uiu_i -{-} viv_i: a bidirectional road between settlements uiu_i and viv_i
  • uiu_i -> viv_i: a directed road from settlement uiu_i to settlement viv_i

Here 1≤ui,vi≤n1 \le u_i, v_i \le n and ui≠viu_i \neq v_i. No two roads connect the same pair of settlements. The settlements and roads form a planar graph. From every settlement on the lake boundary, at least one coastal settlement can be reached.

Output

Print the number of safe plans modulo 109+710^9+7.

Hint

In the first test, a seaport must be built at settlement 66 so that tourist 33 is safe. Tourists 11 and 22 can also reach settlement 66, so they are safe too. Therefore, it does not matter whether seaports are built at settlements 44 and 55.

In the second test, seaports must be built at at least two of settlements 44, 55, and 66, which is enough to keep all tourists safe. It does not matter whether a seaport is built at settlement 77. Checking by hand, there are 88 safe plans in total.

Examples2

  1. Example 1

    Input
    6 8 3 3
    2 -> 1
    2 -> 3
    1 -> 3
    3 -- 6
    1 -> 4
    2 -> 5
    4 -> 6
    4 -- 5
    
    Expected output
    4
    
  2. Example 2

    Input
    8 7 3 4
    1 -> 4
    1 -> 5
    2 -> 4
    2 -> 8
    3 -> 6
    3 -> 5
    8 -> 6
    
    Expected output
    8