#P1144. 最短路计数

最短路计数

Description

Given an undirected, unweighted graph with NN vertices and MM edges, where vertices are numbered 1N1\sim N. Starting from vertex 11, determine how many shortest paths there are to every other vertex.

Input Format

The first line contains 22 positive integers N,MN, M, the number of vertices and edges of the graph.

The next MM lines each contain 22 positive integers x,yx, y, indicating there is an edge connecting vertex xx and vertex yy. Note that self-loops and multiple edges may exist.

Output Format

Output NN lines. The ii-th line contains a non-negative integer: the number of different shortest paths from vertex 11 to vertex ii. Since the answer can be large, you only need to output ansmod100003ans \bmod 100003. If vertex ii is unreachable, output 00.

5 7
1 2
1 3
2 4
3 4
2 3
4 5
4 5

1
1
1
2
4

Hint

From 11 to 55, there are 44 shortest paths: 22 paths 12451\to 2\to 4\to 5 and 22 paths 13451\to 3\to 4\to 5 (because there are 22 edges between 44 and 55).

Constraints:

  • For 20%20\% of the testdata, 1N1001\le N \le 100.
  • For 60%60\% of the testdata, 1N1031\le N \le 10^3.
  • For 100%100\% of the testdata, 1N1061\le N \le 10^6, 1M2×1061\le M \le 2\times 10^6.

Translated by ChatGPT 5