#P7283. [COCI 2020/2021 #4] Janjetina
[COCI 2020/2021 #4] Janjetina
Description
Mr. Malnar will visit cities, labeled with integers to . He also found that there are bidirectional roads, each connecting two of the cities.
On each road there is a restaurant that serves lamb, and for each restaurant we are given the maximum weight of lamb that can be ordered.
He will choose two cities and , and travel from to along a shortest path (i.e., a path that uses the fewest roads). He will stop at exactly one restaurant, namely the one that can provide the largest amount of lamb (if there are multiple such restaurants, he may choose any one), and he will eat all the lamb he orders.
If along a path of length he can eat kilograms of lamb, and , then Mr. Malnar calls it satisfying. The length of a path is equal to the number of roads it uses.
Find how many ordered pairs make the shortest path from to satisfying.
Input Format
The first line contains integers , where is the number of cities.
The next lines each contain three integers , meaning there is a road connecting cities and , and on that road there is a restaurant that provides kilograms of lamb.
Output Format
Output the number of ordered pairs that satisfy the requirement.
3 1
1 2 3
1 3 2
6
4 1
1 2 1
2 3 2
3 4 3
6
5 2
1 2 2
1 3 3
3 4 2
3 5 4
8
Hint
Sample 1 Explanation

The ordered pairs that satisfy the requirement are .
Constraints
This problem uses bundled evaluation.
| Subtask | Points | Constraints and Notes |
|---|---|---|
| City and city () are directly connected (i.e., the shortest distance is ). | ||
| None. |
For all testdata, , , .
Notes
The score setting follows the original COCI problem, with a full score of .
Translated from COCI2020-2021 CONTEST #4 T4 Janjetina.
Translated by ChatGPT 5
京公网安备 11011102002149号