#P10206. [JOI 2024 Final] 建设工程 2 / Construction Project 2

    ID: 11577 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分2024最短路JOI(日本)双指针 two-pointer

[JOI 2024 Final] 建设工程 2 / Construction Project 2

Problem Description

JOI Country has NN train stations, numbered from 11 to NN. In addition, JOI Country has MM undirected railway lines, numbered from 11 to MM. Railway line i (1iM)i\ (1 \leq i \leq M) connects station AiA_i and station BiB_i, and it takes CiC_i 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 u,v (1u<vN)u, v\ (1 \leq u < v \leq N), and build an undirected railway line between station uu and station vv. It takes LL 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 uu and station vv.

If, after building this railway line, it is possible to travel from station SS to station TT in at most KK minutes, the king will be happy. We do not consider transfer time or waiting time.

There are N(N1)2\frac{N(N-1)}{2} ways to choose the two integers u,vu, v. 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 N,MN, M.

The second line contains four integers S,T,L,KS, T, L, K.

Each of the next MM lines contains three integers Ai,Bi,CiA_i, B_i, C_i, representing the ii-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:

  • 2N2×1052 \leq N \leq 2\times 10^5.
  • 1M2×1051 \leq M \leq 2\times 10^5.
  • 1S<TN1 \leq S < T \leq N.
  • 1L1091 \leq L \leq 10^{9}.
  • 1K10151 \leq K \leq 10^{15}.
  • 1Ai<BiN (1iM)1 \leq A_i < B_i \leq N\ (1 \leq i \leq M).
  • (Ai,Bi)(Aj,Bj) (1i<jM)(A_i, B_i) \neq (A_j, B_j)\ (1 \leq i < j \leq M).
  • 1Ci109 (1iM)1 \leq C_i \leq 10^{9}\ (1 \leq i \leq M).

The detailed additional constraints and scores for the subtasks are shown in the table below.

Subtask Additional Constraints Score
1 L=1,K=2,Ci=1 (1iM)L = 1, K = 2, C_i = 1\ (1 \leq i \leq M) 8
2 N50,M50N \leq 50, M \leq 50 16
3 N3000,M3000N \leq 3000, M \leq 3000 29
4 No additional constraints. 47

Translated by ChatGPT 5