This page is still under construction.

Parts of this page are still being built. What you see may change.

Candy-collecting robot

Time limit1sMemory limit512 MB

Summary
Given a house graph with an integer capacity on every corridor, find the maximum number of unit-capacity routes from room 1 to room n.
Level

Medium7 of 10

Topics
Graph, BFS, Implementation, Math
Solved
No attempts yet

Problem

Seokhwan walks around the house and drops candy in the corridors. Seongwon builds a small cleaning robot to clean up the mess.

The house has nn rooms numbered 11 to nn and mm corridors. Each corridor connects two different rooms and can be walked in either direction. Candy lies only in corridors, and each corridor holds a fixed number of candies. Rooms hold no candy.

A robot follows a start room, a destination room, and a route entered by Seongwon. It moves only through corridors that still hold candy, and it picks up exactly 11 candy each time it passes through a corridor. Seongwon enters only routes that satisfy this condition.

Seongwon sends every robot from room 11 to room nn. Determine the largest number of robots that can be set up without taking more candies from any corridor than it holds.

Input

The first line contains the number of rooms nn (2≤n≤3002 \le n \le 300) and the number of corridors mm (1≤m≤50001 \le m \le 5000), separated by a space.

Each of the next mm lines contains corridor information. Each line contains three positive integers aa, bb, and cc, separated by spaces. They mean that the corridor connecting room aa and room bb holds cc candies. (a≠ba \ne b, 1≤a,b≤n1 \le a, b \le n, 1≤c≤1001 \le c \le 100)

Output

Print the largest number of robots that can be sent from room 11 to room nn.

Examples2

  1. Example 1

    Input
    3 2
    1 2 6
    2 3 5
    
    Expected output
    5
    
  2. Example 2

    Input
    4 4
    1 2 7
    1 3 2
    2 3 4
    3 4 10
    
    Expected output
    6