QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#14270. Falling Memories, Maple Sounds

Statistiques

Suppose there are $n$ acupoints on a maple leaf, numbered $1$ to $n$. There are several directed veins connecting these acupoints. The acupoints and veins form a directed acyclic graph (DAG)—referred to as a vein graph (e.g., Figure 1). The numbering of the acupoints is such that acupoint $1$ has no incoming veins from other acupoints; that is, acupoint $1$ only has outgoing veins. As suggested by the story, this DAG contains a tree-like subgraph, which is a tree rooted at acupoint $1$ containing all $n$ acupoints—referred to as a vein tree (e.g., the trees shown in Figure 2 and Figure 3 are both subgraphs of the vein graph given in Figure 1). It is worth noting that there may be multiple possible vein tree configurations in a vein graph; for instance, Figure 2 and Figure 3 are two different vein tree configurations for the vein graph shown in Figure 1.

A vein tree is formally defined as: a vein tree rooted at acupoint $r$ consists of all $n$ acupoints on the maple leaf and $n-1$ veins. The vein tree contains no cycles, nor does it contain any veins from an acupoint to itself. Furthermore, for every acupoint $s$ on the maple leaf, there exists a unique path of veins contained within the vein tree such that one can reach acupoint $s$ from acupoint $r$ by following this path.

Now, add a new vein to the vein graph that is different from any existing vein (note: veins connecting two acupoints but in different directions are considered different veins; for example, a vein from acupoint $3$ to $4$ is different from a vein from $4$ to $3$. Therefore, in Figure 1, one cannot add a vein from $3$ to $4$, but one can add a vein from $4$ to $3$). This new vein can also be from an acupoint to itself (e.g., a vein from $4$ to $4$ can be added in Figure 1). The new vein graph obtained after adding this new vein may contain cycles formed by the veins.

Please calculate the number of vein tree configurations rooted at acupoint $1$ in the new vein graph after adding this vein. Since the number of configurations may be very large, please output the result modulo $1,000,000,007$.

Input

The input file is maple.in. The first line contains four integers $n$, $m$, $x$, and $y$, representing the number of acupoints on the maple leaf, the number of veins, and the new vein to be added from acupoint $x$ to acupoint $y$, respectively. The next $m$ lines each contain two integers, separated by a space, representing a vein. The two integers in the $i$-th line are $u_i$ and $v_i$, representing that the $i$-th vein is from acupoint $u_i$ to acupoint $v_i$.

Output

The output file is maple.out. Output a single line containing the number of vein tree configurations rooted at acupoint $1$ on the maple leaf after adding the vein from $x$ to $y$, modulo $1,000,000,007$.

Examples

Input 1

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

Output 1

3

Note 1

The vein layout is as shown in the figure. Solid lines are veins in the original vein graph, and the dashed line is the newly added vein:

The veins selected in the three vein trees (red veins in the figure below) are: $1 \to 2, 1 \to 3, 2 \to 4$; $1 \to 3, 2 \to 4, 3 \to 2$; $1 \to 2, 2 \to 4, 4 \to 3$.

Input 2

10 16 7 2
1 2
1 8
2 3
2 4
3 5
3 6
4 5
4 6
5 7
6 7
7 10
8 4
8 6
8 9
9 6
9 10

Output 2

92

Constraints

For all test data, $1 \le n \le 100000$, $n - 1 \le m \le \min(200000, n(n - 1) / 2)$, $1 \le x, y, u_i, v_i \le n$.

Test Case ID $n$ Note
1 $n \le 3$
2 $n \le 7$ None
3 $n \le 150$
4 $n \le 100000$
5 $n \le 100000$ No cycle exists after adding the vein from $x$ to $y$
6 $n \le 100000$ None
7 $n \le 100000$ None
8 $n \le 100000$ None
9 $n \le 100000$ None
10 $n \le 100000$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.