Under construction

Still being built. Things may change

Ice Cream

Time limit1sMemory limit512 MB

Summary
Given a capacitated pipe network with a chocolate source, a vanilla source, and a mixing sink, find the maximum flow that reaches the sink with equal chocolate and vanilla amounts.
Level

Hard8 of 10

Topics
Graph, Shortest path, Greedy, Simulation
Solved
No attempts yet

Problem

The Better Get Obese (BGO) ice cream factory is getting ready for the holiday season. After several years of mediocre sales, it has decided to focus only on its most popular product: ice cream with chocolate and vanilla flavour.

To make a perfect such ice cream, the mixing machine must receive equal amounts of vanilla and chocolate ice cream.

The factory has two separate creaming machines that produce chocolate and vanilla ice cream respectively, and the resulting ice cream is stored in two separate tanks. From there it can be transported to the mixing machine through pipes, but the diameter of a pipe gives an upper bound on how much ice cream can pass through it each minute. These pipes meet at welding points, where streams of ice cream go from one pipe to another. At such points, if more than two pipes meet, streams can also merge or split into other streams. Keeping the flavours separate during transportation is not important, since they will eventually be mixed anyway.

Given a map of the pipe system, can you determine how many liters of ice cream the factory can produce each minute?

Input

The first line of input contains two integers n (3 ≤ n ≤ 200) and m (2 ≤ m ≤ 1 000), the number of welding points and the number of pipes, respectively. The second line contains three distinct integers f, c and v (1 ≤ f, c, v ≤ n), the welding points where the mixing machine, the chocolate tank and the vanilla tank are connected to the pipe system, respectively.

Then follow m lines, the ith of which contains three non-negative integers ui, vi and xi (1 ≤ ui, vi ≤ n, 1 ≤ xi ≤ 1 000). These indicate that there is a pipe between welding points ui and vi with a capacity for transporting xi liters of ice cream per minute. Note that several pipes can run in parallel between the same welding points.

Output

Print a single integer, the maximum amount of ice cream the BGO factory can produce each minute (in liters).

Examples1

  1. Example 1

    Input
    3 2
    2 1 3
    1 2 2
    3 2 3
    
    Expected output
    4