PivotOJ

Island Vacation

시간 제한: 2000ms메모리 제한: 1024MB출처: USACO 2024 January PlatinumBOJ 31549

문제

Bessie is taking a vacation in a network of NN (2N1042\le N\le 10^4) islands labeled 1N1\dots N connected by MM bidirectional bridges, each of which connects two islands (N1M3/2(N1)N-1\le M\le 3/2(N-1)). It is guaranteed that the bridges form a connected simple graph (in particular, no two bridges connect the same pair of islands, and no bridge connects an island to itself).

It is also guaranteed that no bridge lies on more than one simple cycle. A simple cycle is a cycle that does not contain repeated islands.

Bessie starts at island 11, and travels according to the following procedure. Supposing she is currently at island ii,

  1. If there are no bridges adjacent to island ii that she has not yet crossed, she ends her vacation.
  2. Otherwise, with probability pi(mod109+7)p_i\pmod{10^9+7}, she ends her vacation.
  3. Otherwise, out of all bridges adjacent to island ii that she has not yet crossed, she chooses one uniformly at random and crosses it.

For each island, output the probability that she ends her vacation at that island, modulo 109+710^9+7.

입력

The first line contains the number of independent test cases TT (1T101\le T\le 10). Consecutive test cases are separated by an empty line.

The first line of each test contains NN and MM, where NN is the number of islands and MM is the number of bridges. It is guaranteed that the sum of NN over all test cases does not exceed 10410^4.

The second line of each test contains p1,p2,,pNp_1, p_2,\dots, p_N (0pi<109+70\le p_i<10^9+7).

The next MM lines of each test describe the bridges. The iith line contains integers uiu_i and viv_i (1ui<viN1\le u_i<v_i\le N), meaning that the iith bridge connects islands uiu_i and viv_i. It is guaranteed that the bridges satisfy the constraints mentioned above.

출력

For each test case, output the probability of ending at each island from 11 to NN modulo 109+710^9+7 on a single line, separated by spaces.

예제

예제 1

입력
2

3 2
0 10 111111112
1 3
2 3

6 5
500000004 0 0 0 0 0
1 5
1 3
4 5
5 6
1 2
출력
0 888888896 111111112
500000004 166666668 166666668 83333334 0 83333334

예제 2

입력
2

5 5
333333336 333333336 0 0 0
1 2
2 3
3 4
4 5
1 5

5 5
0 0 0 0 0
1 2
2 3
2 4
1 4
1 5
출력
777777784 222222224 0 0 0
0 0 333333336 0 666666672

예제 3

입력
1

11 13
2 3 4 5 6 7 8 9 10 11 12
1 2
1 3
2 3
2 4
4 5
2 5
4 8
5 9
2 6
6 7
2 7
6 10
5 11
출력
133332478 200000394 577778352 999999971 399999938 933333282 355555536 800000020 18 600000029 18
코드를 제출하려면 로그인하세요.