AT_abc481_f [ABC481F] Evil Shortest Path
Description
You are given a directed graph with $ N $ vertices and $ M $ edges. The vertices are numbered $ 1,2,\ldots,N $ . The $ i $ -th edge goes from vertex $ A_i $ to vertex $ B_i $ , and a digit $ C_i $ between $ 1 $ and $ 9 $ , inclusive, is written on this edge.
When moving along the edges in their directions, the integer obtained by concatenating the digits written on the traversed edges in the order they are traversed is called the **score** of the movement. For example, if the digits written on the traversed edges are $ 3,1,4 $ in this order, the **score** of the movement is $ 314 $ . The same vertex or edge may be traversed multiple times.
For each $ v=2,3,\ldots,N $ , find the minimum **score** of a movement from vertex $ 1 $ to vertex $ v $ , modulo $ 998244353 $ . Here, it is guaranteed that the given directed graph allows moving from vertex $ 1 $ to every other vertex along the edges in their directions.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ M $ $ A_1 $ $ B_1 $ $ C_1 $ $ A_2 $ $ B_2 $ $ C_2 $ $ \vdots $ $ A_M $ $ B_M $ $ C_M $
Output Format
Print $ N-1 $ lines. The $ (v-1) $ -th line should contain the value found for vertex $ v $ .
Explanation/Hint
### Sample Explanation 1
- For vertex $ 2 $ , $ 1\xrightarrow{1}2 $ gives a score of $ 1 $ .
- For vertex $ 3 $ , $ 1\xrightarrow{1}3 $ gives a score of $ 1 $ .
- For vertex $ 4 $ , $ 1\xrightarrow{1}2\xrightarrow{9}4 $ gives a score of $ 19 $ , and $ 1\xrightarrow{1}3\xrightarrow{2}4 $ gives a score of $ 12 $ , so the minimum is $ 12 $ .
Thus, print $ 1, 1, 12 $ , separated by newlines.
### Sample Explanation 2
- For vertex $ 2 $ , $ 1\xrightarrow{9}2 $ gives a score of $ 9 $ , and $ 1\xrightarrow{2}2 $ gives a score of $ 2 $ , so the minimum is $ 2 $ .
- For vertex $ 3 $ , $ 1\xrightarrow{9}3 $ gives a score of $ 9 $ , and $ 1\xrightarrow{2}2\xrightarrow{1}3 $ gives a score of $ 21 $ , so the minimum is $ 9 $ .
Note that the given graph may contain multi-edges and self-loops.
### Sample Explanation 3
Note that the score should be printed modulo $ 998244353 $ .
### Constraints
- $ 2 \le N \le 2\times 10^5 $
- $ N-1 \le M \le 2\times 10^5 $
- $ 1 \le A_i,B_i \le N $
- $ 1 \le C_i \le 9 $
- All input values are integers.
- It is possible to move from vertex $ 1 $ to every other vertex along the edges in their directions.