#P2149. [SDOI2009] Elaxia的路线

    ID: 1127 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2009各省省选山东拓扑排序最短路

[SDOI2009] Elaxia的路线

Description

Recently, Elaxia and w** have become very close. They want to be together all day, but university studies are intense, so they must plan their time together wisely.

Elaxia and w** commute daily between their dormitories and laboratories. They hope to maximize the time they walk together while still minimizing their own travel time.

You are given the IDs of Elaxia's dormitory and laboratory and w**'s dormitory and laboratory, as well as the school map: the map has nn intersections and mm roads, and traversing each road takes a certain amount of time. Specifically, on an undirected graph, find the longest common path shared by the shortest paths between two pairs of vertices.

Input Format

The first line contains two positive integers n,mn,m, the numbers of vertices and edges.

The second line contains four positive integers x1,y1,x2,y2x_1,y_1,x_2,y_2, which are the IDs of Elaxia's dormitory and laboratory, and w**'s dormitory and laboratory, respectively.

Each of the next mm lines contains three integers u,v,wu,v,w, meaning there is an edge between uu and vv, and it takes ww time to traverse.

Output Format

Output a single integer, the length of the longest common path.

9 10
1 6 7 8
1 2 1
2 5 2
2 3 3
3 4 2
3 9 5
4 5 3
4 6 4
4 7 2
5 8 1
7 9 1
3

Hint

Constraints
For 30%30\% of the testdata, 1n1001\le n \le 100.
For 60%60\% of the testdata, 1n10001\le n \le 1000.
For 100%100\% of the testdata, 1n15001\le n \le 1500, 1m3×1051 \leq m \leq 3 \times 10^5, 1w1041\le w \le 10^4. The input guarantees there are no multiple edges or self-loops.

Translated by ChatGPT 5