Description
Problem H
Morning Walk
Time Limit
3 Seconds
Kamal is a Motashota guy. he has got a new job in Chittagong. so, he has moved to Chittagong from Dinajpur. he was getting fatter in Dinajpur as he had no work in his hand there. so, moving to Chittagong has turned to be a blessing for him. every morning he takes a walk through the hilly roads of charming city Chittagong. he is enjoying this city very much. there are so many roads in Chittagong and every morning he takes different paths for his walking. but while choosing a path he makes sure he does not visit a road twice not even in his way back home. an intersection point of a road is not considered as the part of the road. in a sunny morning, he was thinking about how it wocould be if he cocould visit all the roads of the city in a single walk. your task is to help Kamal in determining whether it is possible for him or not.
Input
Input will consist of several test cases. each test case will start with a line containing two numbers. the first number indicates the number of road intersections and is denoted byN (2 ≤n ≤200 ). the road intersections are assumed to be numbered from0 to N-1. the second numberR denotes the number of roads (0 ≤r ≤10000 ). then there will beR lines each containing two numbersc1 andc2 indicating the intersections ing a road.
Output
Print a single line containing the text "Possible" without quotes if it is possible for Kamal to visit all the roads exactly once in a single walk otherwise print "Not Possible ".
Sample Input
Output for Sample Input
2 2
0 1
1 0
2 1
0 1
Possible
Not Possible
Problemsetter: Muhammad Abul Hasan
International Islamic University Chittagong
Note that an edge is not an undirected edge. Multiple undirected edges can exist between two points.
The following is an error and the AC code... Multi-connection branch does not work...
Algorithm: It is good to judge whether the graph is connected and contains Euler's loop. Therefore, you only need to check whether the number of recorded points is zero and whether it is an even number. If and only when the graph is connected and the degrees of all vertices are even, the output Possible :).
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Define N 202
Using namespace std;
Int u [N];
Int main (){
Int r, n;
While (cin> n> r ){
Memset (u, 0, sizeof (u ));
For (int I = 0; I <r; I ++ ){
Int t1, t2;
Cin> t1> t2;
U [t1] ++;
U [t2] ++;
}
Int I;
For (I = 0; I <n; I ++ ){
If (! U [I] | (u [I] & 1) break;
}
If (I = n) cout <"Possible" <endl;
Else cout <"Not Possible" <endl;
}
Return 0;
}
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Define N 202
Using namespace std;
Int u [N];
Int main (){
Int r, n;
While (cin> n> r ){
Memset (u, 0, sizeof (u ));
For (int I = 0; I <r; I ++ ){
Int t1, t2;
Cin> t1> t2;
U [t1] ++;
U [t2] ++;
}
Int I;
For (I = 0; I <n; I ++ ){
If (! U [I] | (u [I] & 1) break;
}
If (I = n) cout <"Possible" <endl;
Else cout <"Not Possible" <endl;
}
Return 0;
}