QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#22516. Silver Cow Party

İstatistikler

One cow from each of $N$ farms ($1 \le N \le 1000$) conveniently numbered $1..N$ is going to attend the big cow party to be held at farm #$X$ ($1 \le X \le N$). A total of $M$ ($1 \le M \le 100,000$) unidirectional (one-way roads connects pairs of farms; road $i$ requires $T_i$ ($1 \le T_i \le 100$) units of time to traverse.

Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.

Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?

Input

Read the input from standard input.

  • Line 1: Three space-separated integers, respectively: $N$, $M$, and $X$

Lines $2..M+1$: Line $i+1$ describes road $i$ with three space-separated integers: $A_i$, $B_i$, and $T_i$. The described road runs from farm $A_i$ to farm $B_i$, requiring $T_i$ time units to traverse.

Output

Write the output to standard output.

  • Line 1: One integer: the maximum of time any one cow must walk.

Examples

Input 1

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

Output 1

10

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.

Problem credits: USACO 2007 February Silver

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.