QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#3729. Directed Acyclic Graph

Statistics

Bobo has a directed acyclic graph (DAG) with $n$ vertices and $m$ edges (i.e., for any vertex $v$, there is no path starting and ending at $v$).

For convenience, the vertices are labeled $1, 2, \dots, n$. Let $\mathrm{count}(x, y)$ denote the number of distinct paths from vertex $x$ to vertex $y$ (with the convention that $\mathrm{count}(x, x) = 0$). Bobo wants to know the value of $$\sum_{i = 1}^n\sum_{j = 1}^n \mathrm{count}(i, j) \cdot a_i \cdot b_j$$ modulo $(10^9+7)$.

Here, $a_i$ and $b_j$ are given sequences.

Input

The input contains no more than $15$ test cases.

The first line of each test case contains two integers $n, m$ ($1 \leq n, m \leq 10^5$).

The next $n$ lines, the $i$-th line contains two integers $a_i, b_i$ ($0 \leq a_i, b_i \leq 10^9$).

The last $m$ lines, the $i$-th line contains two integers $u_i, v_i$, representing a directed edge from vertex $u_i$ to $v_i$ ($1 \leq u_i, v_i \leq n$).

Output

For each test case, output a single integer representing the required value.

Examples

Input 1

3 3
1 1
1 1
1 1
1 2
1 3
2 3
2 2
1 0
0 2
1 2
1 2
2 1
500000000 0
0 500000000
1 2

Output 1

4
4
250000014

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.