The Road to the Classroom
Time limit3sMemory limit128 MB
Decide whether K routes from intersection 1 to intersection 2 exist that are internally vertex-disjoint and edge-disjoint on an undirected graph.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Implementation, Brute force
- Solved
- No attempts yet
Problem
A class has students in total, and some of them dislike each other intensely. Students who dislike each other never want to run into one another anywhere outside the classroom on their way to school. Every student starts at intersection and walks to intersection , where the classroom is. Determine whether the students can be assigned distinct routes such that, apart from the start () and the destination (), no two routes share any intersection or any road.
Input
The input consists of several test cases.
The first line of each test case contains the number of routes to assign, , and the number of intersections, . The intersections are numbered from to . Among the following lines, the -th line lists, in increasing order, the numbers of the intersections directly connected to intersection . Every intersection is connected to at least one other intersection.
The last line of the input is 0 0, which should not be processed.
and . Every student starts at intersection , and the classroom is at intersection .
Output
For each test case, first print the case number in the format Case x: (numbering starts at ). On the next line, print Possible if routes satisfying the condition can be assigned, or Impossible otherwise.
After the result of each test case, print one blank line.