School Road
Time limit2sMemory limit1024 MB
Given a weighted connected graph and shortest distance L from city 1 to city N, decide whether a simple path from N back to 1 longer than L exists.
- Level
Medium7 of 10
- Topics
- Shortest path, Graph, DFS
- Solved
- No attempts yet
Problem
Beaverland consists of cities, numbered from to . There are roads connecting cities, numbered from to . Road () connects city and city in both directions, and its length is . You can travel from any city to any other city by passing through some number of roads.
Bitaro is a beaver who lives in city . He goes to school in city . He usually takes the same route to school. That route satisfies the following conditions.
- Let be the minimum distance from city to city .
- Bitaro's route to school connects city and city , and its length is .
Today is a fine day, so Bitaro decides to take a roundabout way home. He will take a route from city to city that is longer than . Bitaro gets bored easily, so he does not want to visit the same city more than once. On the way home, he may not visit the same city twice, and he may not turn back.
Given the cities and roads of Beaverland, write a program that determines whether a roundabout way from school to Bitaro's home exists.
Input
The first line contains and .
Output
Write one line. Print if there is a route from city to city that is longer than and visits no city more than once. Otherwise, print .
Constraints
- .
- .
- ().
- () ().
- You can travel from any city to any other city by passing through some number of roads.