#P16252. [蓝桥杯 2026 省研究生组] 通信链路
[蓝桥杯 2026 省研究生组] 通信链路
Problem Description
Xiao Lan is an employee of a communication network company, and he is doing some statistics work.
The communication network consists of relay stations and communication links. Transmitting information through one link takes a certain amount of time. If information is transmitted from one relay station to another through several links, the total delay is the sum of the time costs of all links. Since the capacity of a link is limited, suppose a link connects relay stations and . If it takes time to transmit information from to , then it takes time to transmit information from to .
Xiao Lan only cares about the ones digit of the total delay. For an ordered pair of different relay stations , if information can be transmitted from to through several links, and the ones digit of the total delay is , then Xiao Lan calls -harmonious. Since the delay from to may differ from the delay from to , and should be considered different relay-station pairs, and pairs like are invalid.
Now, Xiao Lan wants you to help him find how many relay-station pairs are 0-harmonious, 1-harmonious, 2-harmonious, , 9-harmonious.
Input Format
The input contains multiple lines. The first line contains two positive integers , representing the number of relay stations and the number of links.
The next lines each contain three positive integers , meaning there is a link between relay stations and , and transmitting information along this link from to takes time ; transmitting from to takes time .
The given network may contain multiple edges or self-loops.
Output Format
Output a total of 10 lines. Each line contains one positive integer, representing the number of 0-harmonious, 1-harmonious, , 9-harmonious relay-station pairs, in order.
3 3
1 2 1
2 3 2
3 1 2
0
1
2
2
1
0
1
2
2
1
Hint
Sample Explanation
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| / | (1,2) | (2,3),(3,1) | (1,3),(3,2) | (2,1) | / | (1,2) | (2,3),(3,1) | (1,3),(3,2) | (2,1) |
The table above lists the relay-station pairs that are -harmonious. For example, there exists a communication route whose total delay is , and the ones digit is , so the pair is 6-harmonious.
A relay-station pair may be both -harmonious and -harmonious for different and . For one relay-station pair, there may be multiple communication routes whose total delay has ones digit , but it should only be counted once. For example, the total delay of is , which also has ones digit , but is counted only once among the 6-harmonious pairs.
Constraints and Notes for Test Cases
For of the data, .
For another of the data, .
For another of the data, and any two relay stations can definitely transmit information through links.
For of the data, $2 \leq n \leq 100000, 0 \leq m \leq 200000, 1 \leq x_i, y_i \leq n, 1 \leq w_i < 20$.
Translated by ChatGPT 5