Problem:
Score : 800 points

Problem Statement

You are given a simple connected undirected graph consisting of N vertices and M edges.
The vertices are numbered 1 to N, and the edges are numbered 1 to M.

Edge i connects Vertex a_i and b_i bidirectionally.

Determine if three circuits (see Notes) can be formed using each of the edges exactly once.

Notes

A circuit is a cycle allowing repetitions of vertices but not edges.

Constraints

All values in input are integers.

1 \leq N,M \leq 10^{5}

1 \leq a_i, b_i \leq N

The given graph is simple and connected.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
:
a_M b_M

Output

If three circuits can be formed using each of the edges exactly once, print Yes; if they cannot, print No.

Sample Input 1

7 9
1 2
1 3
2 3
1 4
1 5
4 5
1 6
1 7
6 7

Sample Output 1

Yes

Three circuits can be formed using each of the edges exactly once, as follows:

Sample Input 2

3 3
1 2
2 3
3 1

Sample Output 2

No

Three circuits are needed.

Sample Input 3

18 27
17 7
12 15
18 17
13 18
13 6
5 7
7 1
14 5
15 11
7 6
1 9
5 4
18 16
4 6
7 2
7 11
6 3
12 14
5 2
10 5
7 8
10 15
3 15
9 8
7 15
5 16
18 15

Sample Output 3

Yes

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for i in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push((b, i));
        graph[b].push((a, i));
    }

    let ge_six = graph.iter().filter(|g| g.len() >= 6).count();

    let all_even = graph.iter().all(|g| g.len() % 2 == 0);
    if !all_even {
        println!("No");
    } else if ge_six > 0 {
        println!("Yes");
    } else if graph.iter().filter(|g| g.len() == 4).count() >= 3 {
        println!("Yes");
    } else if graph.iter().filter(|g| g.len() == 4).count() <= 1 {
        println!("No");
    } else {
        let four2 = (0..n).filter(|&i| graph[i].len() == 4).collect::<Vec<_>>();

        let f1 = four2[0];
        let f2 = four2[1];

        let mut reach_f1 = 0;

        let mut used = vec![false; m];
        for i in 0..4 {
            assert!(!used[graph[f1][i].1]);
            used[graph[f1][i].1] = true;
            let mut cur = graph[f1][i].0;
            while cur != f1 && cur != f2 {
                assert_eq!(graph[cur].len(), 2);
                let next = &graph[cur];
                let i = if used[next[0].1] { 1 } else { 0 };
                assert!(!used[next[i].1]);
                used[next[i].1] = true;
                cur = next[i].0;
            }
            if cur == f1 {
                reach_f1 += 1;
            }
        }

        if reach_f1 == 2 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}