#P3244. [HNOI2015] 落忆枫音

    ID: 2293 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp递推2015湖南拓扑排序

[HNOI2015] 落忆枫音

Description

Assume there are nn acupoints on a maple leaf, numbered 1n1 \sim n. Several directed veins connect these acupoints.

The acupoints and veins form a directed acyclic graph—called the vein graph (for example, Figure 11). The numbering of the acupoints ensures that acupoint 11 has no incoming veins from other acupoints, that is, acupoint 11 only has outgoing veins. As the story above suggests, this directed acyclic graph contains a tree-shaped subgraph: a tree rooted at acupoint 11 that spans all nn acupoints—called a vein-tree (for example, the trees in Figure 22 and Figure 33 are both vein-trees of the vein graph given by Figure 11).

Note that there may be multiple vein-tree schemes in the vein graph. For example, Figure 22 and Figure 33 are two different vein-tree schemes for the vein graph in Figure 11.

A formal definition of a vein-tree is as follows: a vein-tree rooted at acupoint rr consists of all nn acupoints and (n1)(n-1) veins. There are no cycles in the vein-tree, nor self-loops. Moreover, for every acupoint ss on the leaf, there exists a unique vein path contained in the vein-tree such that starting from acupoint rr and following this path you can reach acupoint ss.

Now we add one new vein, different from all existing veins, to the vein graph (note: veins connecting the same two acupoints but in opposite directions are considered different. For example, the vein from acupoint 33 to 44 is different from the vein from 44 to 33. Therefore, in Figure 11, you cannot add a vein from 33 to 44, but you may add a vein from 44 to 33). This new vein may be a self-loop (for example, in Figure 1, a vein from 44 to 44 can be added).

After adding this new vein, cycles formed by veins may appear in the new vein graph. Please compute the number of vein-tree schemes rooted at acupoint 11 in the new vein graph after adding this vein.

Since the number of schemes may be very large, output it modulo (109+7)(10^9+7).

Input Format

The first line contains four integers n,m,x,yn, m, x, y, representing the number of acupoints on the leaf, the number of veins, and that the vein to be added goes from acupoint xx to acupoint yy.

The next mm lines each contain two integers separated by a space, representing one existing vein.

In line ii, the two integers are uiu_i and viv_i, meaning the ii-th vein goes from acupoint uiu_i to acupoint viv_i.

Output Format

Output one line: the number of vein-tree schemes rooted at acupoint 11 on the leaf after adding the vein from xx to yy, modulo (109+7)(10^9+7).

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

Hint

For all testdata, it is guaranteed that:

  • 1n1000001 \leq n \leq 100000.
  • n1mmin(200000,n(n1)/2)n - 1 \leq m \leq \min(200000, n(n - 1)/2).
  • 1x,y,ui,vin1 \leq x, y, u_i, v_i \leq n.

Fixed by Starrykiller.

Translated by ChatGPT 5