#P2505. [HAOI2012] 道路

    ID: 1520 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2012河南各省省选拓扑排序最短路

[HAOI2012] 道路

Description

Country C has nn cities connected by mm directed roads. A path is called a shortest path if and only if there does not exist another path from its start to its end whose total length is smaller. Two shortest paths are different if and only if the sequences of roads they contain are different. We need to assess the importance of each road by counting how many different shortest paths pass through that road. Now, this task is given to you.

Input Format

The first line contains two positive integers n,mn, m.

Each of the next mm lines contains three positive integers u,v,wu, v, w, indicating there is a road from uu to vv with length ww.

Output Format

Output mm lines. The ii-th line contains one number: the number of shortest paths that pass through the ii-th road, modulo 109+710^9+7.

4 4
1 2 5
2 3 5
3 4 5
1 4 8
2
3
2
1

Hint

Constraints

30%30\% of the testdata satisfies: n15,m30n \le 15, m \le 30.

60%60\% of the testdata satisfies: n300,m1000n \le 300, m \le 1000.

100%100\% of the testdata satisfies: n1500,m5000,1w10000n \le 1500, m \le 5000, 1 \le w \le 10000.

Multiple edges may exist.

Translated by ChatGPT 5