Candy-collecting robot
Time limit1sMemory limit512 MB
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 rooms numbered to and 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 candy each time it passes through a corridor. Seongwon enters only routes that satisfy this condition.
Seongwon sends every robot from room to room . 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 () and the number of corridors (), separated by a space.
Each of the next lines contains corridor information. Each line contains three positive integers , , and , separated by spaces. They mean that the corridor connecting room and room holds candies. (, , )
Output
Print the largest number of robots that can be sent from room to room .