ABCDE
InterviewTime limit2sMemory limit512 MB
Given an undirected friendship graph, decide whether it contains a simple path of five distinct vertices, that is, a path with four edges.
- Level
Medium5 of 10
- Topics
- Graph, DFS, Backtracking, Brute force
- Solved
- No attempts yet
Problem
An algorithm camp has participants. They are numbered from to , and some pairs of them are friends.
Decide whether there are people A, B, C, D, E with all of the following friendships.
- A and B are friends.
- B and C are friends.
- C and D are friends.
- D and E are friends.
A, B, C, D, E must be five different people. Write a program that decides whether such five people exist.
Input
The first line contains the number of people () and the number of friendships ().
Each of the next lines contains two integers and , meaning that person and person are friends. (, ) The same friendship is never given more than once. Friendship has no direction, so if is a friend of , then is a friend of .
Output
Print 1 if A, B, C, D, E satisfying the conditions exist, and 0 otherwise.