#P1821. [USACO07FEB] Cow Party S

[USACO07FEB] Cow Party S

Description

Winter break has arrived, and nn cows are going to attend a party held at the farm of the cow numbered xx. There are mm directed roads between farms, and each road has a certain length.

After the party, every cow must return home. Whether going to the party or going back home, each cow will choose the shortest path. Among these nn cows, find the maximum length of a shortest round-trip path.

Input Format

The first line contains three integers representing the number of cows nn, the number of roads mm, and the party farm index xx.
The next mm lines each contain three integers u,v,wu, v, w, indicating that there is a road from uu to vv with length ww.

Output Format

Output one line with one integer representing the answer.

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

10

Hint

Sample 1 Explanation

Constraints For all test points, it is guaranteed that 1xn1031 \leq x \leq n \leq 10^3, 1m1051 \leq m \leq 10^5, 1u,vn1 \leq u, v \leq n, 1w1021 \leq w \leq 10^2. It is guaranteed that from any node you can reach node xx, and from xx you can reach all other nodes.

Translated by ChatGPT 5