This page is still under construction.

Parts of this page are still being built. What you see may change.

ABCDE

Interview

Time limit2sMemory limit512 MB

Summary
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 NN participants. They are numbered from 00 to N−1N-1, 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 NN (5≤N≤20005 \le N \le 2000) and the number of friendships MM (1≤M≤20001 \le M \le 2000).

Each of the next MM lines contains two integers aa and bb, meaning that person aa and person bb are friends. (0≤a,b≤N−10 \le a, b \le N-1, a≠ba \ne b) The same friendship is never given more than once. Friendship has no direction, so if aa is a friend of bb, then bb is a friend of aa.

Output

Print 1 if A, B, C, D, E satisfying the conditions exist, and 0 otherwise.

Examples4

  1. Example 1

    Input
    5 4
    0 1
    1 2
    2 3
    3 4
    
    Expected output
    1
    
  2. Example 2

    Input
    5 5
    0 1
    1 2
    2 3
    3 0
    1 4
    
    Expected output
    1
    
  3. Example 3

    Input
    6 5
    0 1
    0 2
    0 3
    0 4
    0 5
    
    Expected output
    0
    
  4. Example 4

    Input
    8 8
    1 7
    3 7
    4 7
    3 4
    4 6
    3 5
    0 4
    2 7
    
    Expected output
    1