#P10206. [JOI 2024 Final] 建设工程 2 / Construction Project 2
[JOI 2024 Final] 建设工程 2 / Construction Project 2
Problem Description
JOI Country has train stations, numbered from to . In addition, JOI Country has undirected railway lines, numbered from to . Railway line connects station and station , and it takes minutes to travel from one station to the other.
You are the minister of JOI Country and decide to build a new railway line in the following way:
Choose two integers , and build an undirected railway line between station and station . It takes minutes to travel from one station to the other. Note that you may build it even if there is already a railway line connecting station and station .
If, after building this railway line, it is possible to travel from station to station in at most minutes, the king will be happy. We do not consider transfer time or waiting time.
There are ways to choose the two integers . You want to know how many of these ways will make the king happy.
Given the information about the stations and railway lines, as well as the king’s requirement, write a program to compute how many ways of choosing the two integers will make the king happy.
Input Format
The first line contains two integers .
The second line contains four integers .
Each of the next lines contains three integers , representing the -th undirected railway line.
Output Format
Output one line containing one integer, the number of ways to choose the two integers that will make the king happy.
7 8
6 7 1 2
1 2 1
1 6 1
2 3 1
2 4 1
3 5 1
3 7 1
4 5 1
5 6 1
4
3 2
1 3 1 2
1 2 1
2 3 1
3
6 4
2 5 1000000000 1
1 2 1000000000
2 3 1000000000
2 4 1000000000
5 6 1000000000
0
18 21
4 8 678730772 3000000062
5 13 805281073
8 17 80983648
3 8 996533440
10 16 514277428
2 5 57914340
6 11 966149890
8 12 532734310
2 9 188599710
2 3 966306014
12 16 656457780
16 18 662633078
1 15 698078877
2 8 665665772
2 6 652261981
14 15 712798281
7 13 571169114
13 14 860543313
6 7 454251187
9 14 293590683
6 14 959532841
3 11 591245645
16
Hint
For all input data, the following constraints hold:
- .
- .
- .
- .
- .
- .
- .
- .
The detailed additional constraints and scores for the subtasks are shown in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
| 1 | 8 | |
| 2 | 16 | |
| 3 | 29 | |
| 4 | No additional constraints. | 47 |
Translated by ChatGPT 5