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 C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t max_size;
} graph;

graph* newGraph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void freeGraph (graph *g) {
  free (g->edge);
  free (g->start);
  free (g);
  return;
}

void addEdge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->max_size) {
    g->max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

typedef int32_t i32;

int can (i32 now, uint8_t *used, i32 *visited, graph *g) {
  for (i32 p = g->start[now]; p != -1; p = g->edge[p].next) {
    if (used[p/2]) continue;
    used[p/2] = 1;
    i32 u = g->edge[p].vertex;
    if (visited[u]) {
      //printf("%" PRIi32 " - %" PRIi32, u, now);
      visited[u] = -1;
      return 1;
    }
    visited[u] = 1;
    int c = can (u, used, visited, g);
    if (c == 1) {
      c = visited[now] < 0 ? 2 : 1;
      //printf(" (%d) ", c);
      //if (c==2){puts("");}
      return c;
    } 
    used[p/2] = 0;
    if (c == 2) {
      return 2;
    }
  }
  return 0;
}

void run (void) {
  i32 n, m;
  scanf("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *cnt = (i32 *) calloc (n, sizeof (i32));
  graph *g = newGraph (n);
  for (i32 i = 0; i < m; ++i) {
    i32 a, b;
    scanf("%" SCNi32 "%" SCNi32, &a, &b);
    a--;b--;
    addEdge (g, a, b);
    addEdge (g, b, a);
    cnt[a]++;
    cnt[b]++;
  }
  for (i32 i = 0; i < n; ++i) {
    if (cnt[i] & 1) {
      puts ("No");
      return;
    }
  }
  uint8_t *used = (uint8_t *) calloc (m, sizeof (uint8_t));
  i32 *visited = (i32 *) calloc (n, sizeof (i32));
  for (i32 iter = 0; iter < 3; ++iter) {
    memset (visited, 0, sizeof (i32) * n);
    visited[0] = 1;
    int c = can(0, used, visited, g);
    if (c == 0) {
      puts ("No");
      return;
    }
  }
  puts("Yes");
}

int main (void) {
  run ();
  return 0;
}