AlgoUniversity
  • Go Back
Discussion
Guesstimate Loss :

Author

Rishabh Verma

Difficulty Level : Hard

Submissions : 756

Asked In : Morgan-Stanley

Marks :50

: 2 | : 7

An Online Taxi service is facing losses due to recent changes in its discount prices. To overcome the losses, the team has made a list of N places of a city with M routes. Each route has 3 components.

The first component is the pick-up position id, the second is the destination position id and the third is the cost per trip between the pickup and destination. If cost is +ve, company is making a profit else loss from that trip. If the pick-up and destination point are same, then that trip is known as a round trip.

Write an algorithm for the company's system that will calculate the maximum amount of money that they are losing in a round trip.

In case there is no round trip having -ve cost 0 loss is always the option.

Input

First line contains two space separated integers number of cities N and number of routes M. (1≤N,M≤10000).

Next M lines contains 3 space separated integers U,V and W (Pick-up Position , destination and cost respectively) (0≤U,V<N) and (−1000≤W≤1000).

Output

Print a singe integer denoting the minimum amount of money that they are losing in a round trip.

Examples

Input
4 5
0 1 -1
1 2 -2
2 0 -5
0 3 6
3 0 -19
Output
-13
Input
4 5
0 1 -1
1 2 -2
2 0 -5
0 3 6
3 2 3
Output
-8

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.