#K93682. Knight's Maximum Toll

    ID: 38474 Type: Default 1000ms 256MiB

Knight's Maximum Toll

Knight's Maximum Toll

In a distant medieval kingdom, villages are connected by one-way roads, each with an associated toll fee. A brave knight is tasked with collecting these tolls while journeying from a specified starting village. However, due to the risk of being captured, the knight cannot visit any village more than once. Your task is to determine the maximum toll fee the knight can collect following these constraints.

If the knight travels along a path from the starting village (s) through a sequence of villages (v_1, v_2, \dots, v_k), collecting toll fees (t_1, t_2, \dots, t_k) respectively, then the total toll is given by (\sum_{i=1}^{k} t_i). Optimize his route to maximize the collected toll fee.

inputFormat

The first line contains three integers (n), (m), and (s), where (n) is the number of villages, (m) is the number of roads, and (s) is the starting village. Each of the next (m) lines contains three integers (u), (v), and (t) representing a one-way road from village (u) to village (v) with a toll fee (t).

outputFormat

Print a single integer representing the maximum toll the knight can collect without revisiting any village.## sample

5 7 1
1 2 5
1 3 10
2 3 2
2 4 4
3 4 1
3 5 5
4 5 3
15