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



Sample input:
7 9
1 2
1 3
2 3
1 4
1 5
4 5
1 6
1 7
6 7


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
# class Graph:
#     def __init__(self, V: int):
#         self.__V = V
#         self.__g = [[] for _ in range(V)]
#         self.__used = [False] * V

#     def add_edge(self, u: int, v: int, cap: int):
#         self.__g[u].append((v, cap, len(self.__g[v])))
#         self.__g[v].append((u, 0, len(self.__g[u])-1))

#     def ford_fulkerson(self, s: int, t: int)->int:
#         flow = 0
#         while True:
#             self.__used = [False] * self.__V
#             f = self.__dfs(s, t, float('inf'))
#             if f == 0:
#                 break
#             flow += f
#         return flow

#     def __dfs(self, v: int, t: int, f: int)->int:
#         if v == t:
#             return f
#         self.__used[v] = True

#         for i, (to, cap, rev) in enumerate(self.__g[v]):
#             if (not self.__used[to]) and cap > 0:
#                 d = self.__dfs(to, t, min(f, cap))

#                 if d > 0:
#                     self.__g[v][i] = (to, cap-d, rev)

#                     _to, _cap, _rev = self.__g[to][rev]
#                     self.__g[to][rev] = (_to, _cap+d, _rev)

#                     return d
#         return 0


class Queue:
    def __init__(self):
        self.__count = 0
        self.__data = []

    def count(self) -> int:
        return self.__count

    def empty(self) -> bool:
        return self.__count == 0

    def front(self):
        if self.empty():
            raise Exception('empty')
        return self.__data[0]

    def dequeue(self):
        if self.empty():
            raise Exception('empty')
        res, self.__data = self.__data[0], self.__data[1:]
        self.__count -= 1
        return res

    def enqueue(self, v):
        self.__data.append(v)
        self.__count += 1


class Edge:
    def __init__(self, v: int, cap: int, rev: int):
        """
        :param v: to
        :param cap: capacity
        :param rev: revesed to
        """
        self.v = v
        self.cap = cap
        self.rev = rev

        self.flow = 0


class Graph:
    def __init__(self, num_v: int):
        """
        :param num_v: number of vertex
        """
        self.num_v = num_v
        self.level = [0] * num_v
        self.graph = [[] for _ in range(num_v)]

    def add_edge(self, u: int, v: int, cap: int):
        """add edge
        :param u: from
        :param v: to
        :param cap: capacity
        """
        forward = Edge(v, cap, len(self.graph[v]))
        back = Edge(u, 0, len(self.graph[u]))

        self.graph[u].append(forward)
        self.graph[v].append(back)

    def __bfs(self, s: int, t: int) -> bool:
        """Finds if more flow can be sent from s to t.
        Also assigns level to nodes.
        :param s: source
        :param t: sink
        :return: `True` if finds more flow can be sent from s to t.
        """
        self.level = [-1] * self.num_v
        self.level[s] = 0

        q = Queue()
        q.enqueue(s)
        while not q.empty():
            u = q.dequeue()

            for e in self.graph[u]:
                # not yet visited, and flow can be sent more
                if self.level[e.v] < 0 and e.flow < e.cap:
                    # level of v is level of its parent + 1
                    self.level[e.v] = self.level[u] + 1

                    q.enqueue(e.v)

        return self.level[t] >= 0

    def __send_flow(self,
                    u: int, flow: int, t: int, start: list = None) -> int:
        """send `flow` from `u` to `t`.
        :param u: from
        :param flow: flow
        :param t: to
        :param start: explored vertex
        :return: value of flow can be sent from u to t.
        """
        if u == t:
            return flow

        if start is None:
            start = [0] * (self.num_v + 1)

        while start[u] < len(self.graph[u]):
            e = self.graph[u][start[u]]

            if self.level[e.v] != self.level[u] + 1:
                # skip if level of e.v is not next to
                # u's one.
                start[u] += 1
                continue
            if not (e.flow < e.cap):
                # skip if flow cannot be sent more to
                # v.
                start[u] += 1
                continue

            cur_f = min(flow, e.cap - e.flow)
            tmp_f = self.__send_flow(e.v, cur_f, t, start)

            if tmp_f > 0:
                # add flow to current edge
                e.flow += tmp_f
                # subtract flow from reverse edge of current one.
                self.graph[e.v][e.rev].flow -= tmp_f

                return tmp_f

            start[u] += 1

        return 0

    def maximum_flow(self, s: int, t: int) -> int:
        """maximum flow from s to t.
        :param s: from
        :param t: to
        :return: maximum flow
        """
        if s == t:
            return 0

        max_flow = 0
        while self.__bfs(s, t):
            while True:
                flow = self.__send_flow(s, float('inf'), t)
                if flow == 0:
                    break
                max_flow += flow
        return max_flow


def three_circuits(N: int, M: int, edges: list)->bool:
    d = [0] * N

    for u, v in edges:
        d[u-1] += 1
        d[v-1] += 1

    if any(v & 1 == 1 for v in d):
        # euler 閉路でないなら NG
        return False
    if any(v >= 6 for v in d):
        # 次数が 6 以上のものがあれば OK
        return True

    c4 = d.count(4)
    if c4 > 2:
        # 次数が 4 のものが 3 つ以上存在すれば OK
        return True
    if c4 < 2:
        # 次数が 4 のものが 1 つ以下なら NG
        return False

    # 次数が 4 のものが 2 つならその二つの頂点間にパスが二つ
    # の時のみ OK
    # graph = Graph(N)
    # print('-' * 30)
    # for u, v in edges:
    #     print(u-1, v-1)
    #     graph.add_edge(u-1, v-1, 1)
    #     graph.add_edge(v-1, u-1, 1)

    # u = d.index(4)
    # v = d.index(4, u+1)

    # return graph.maximum_flow(u, v) == 2
    return False


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    edges = [tuple(map(int, input().split())) for _ in range(M)]
    yes = three_circuits(N, M, edges)
    print('Yes' if yes else 'No')

Submission status: Wrong Answer

Solution code:
import sys

def ta(x, y, p):
    xc = 0
    yc = 0

    for i in p[x]:
        c = i
        while True:
            if c == x:
                xc += 1
                break
            elif c == y:
                yc += 1
                break
            cs = p[c]
            for j in cs:
                if j != c:
                    c = j
                    break
    if xc == yc:
        return True
    else:
        return False


d = {}
p = {}
n, m = input().strip().split(" ")
for i in range(int(n)):
    i += 1
    d[i] = 0
    p[i] = list()

for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    d[x] += 1
    d[y] += 1
    p[x].append(y)
    p[y].append(x)

r = None
fc = 0
fcs = []
for x in d.values():
    if x % 2 != 0:
        r = False
        break
    if x >= 6:
        r = True
    if x >= 4:
        fc += 1
        fcs.append(x)

if r == None:
    if fc >= 3:
        r = True
    elif fc == 2:
        x, y = fcs
        r = ta(x, y, p)
    else:
        r = False
if r:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
def input():
	return sys.stdin.readline()[:-1]

n, m = map(int, input().split())
deg = [0 for _ in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	deg[a-1] += 1
	deg[b-1] += 1

ng = False
cnt = 0
cntMax = 0
two, four, six = 0, 0, 0
for i in range(n):
	if deg[i]%2 == 1:
		ng = True
	elif deg[i] > 6:
		cnt += (deg[i]-6) // 2
		cntMax = max(cntMax, (deg[i]-6) // 2)
	elif deg[i] == 2:
		two += 1
	elif deg[i] == 4:
		four += 1
	else:
		six += 1

#print(deg)
#print(two, four, six)
two -= max(2*cntMax - cnt, 0)

if six == 0 and four <= 1:
	ng = True
else:
	if four == 0 and six == 1 and two < 3:
		ng = True
	elif four == 2 and six == 2 and two < 2:
		ng = True
	elif four == 1 and six == 1 and two < 1:
		ng = True

if ng:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
def input():
	return sys.stdin.readline()[:-1]

n, m = map(int, input().split())
deg = [0 for _ in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	deg[a-1] += 1
	deg[b-1] += 1

ng = False
cnt = 0
two, four, six = 0, 0, 0
for i in range(n):
	if deg[i]%2 == 1:
		ng = True
	elif deg[i] > 6:
		cnt += (deg[i]-6) // 2
	elif deg[i] == 2:
		two += 1
	elif deg[i] == 4:
		four += 1
	else:
		six += 1

#print(deg)
#print(two, four, six)
two -= cnt
if six == 0 and four <= 1:
	ng = True
else:
	if four == 0 and six == 1 and two < 3:
		ng = True
	elif four == 2 and six == 2 and two < 2:
		ng = True
	elif four == 1 and six == 1 and two < 1:
		ng = True

if ng:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 14:57:43 2019

@author: Yamazaki Kenichi
"""
import sys

N,M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(M)]

T = [[0 for i in range(N+1)] for i in range(N+1)]
for c in A:
    T[c[0]][c[1]] = 1
    T[c[1]][c[0]] = 1

flg = False
memo = []
for i in range(1,N+1):
    if sum(T[i])%2 != 0:
        print('No')
        sys.exit()
    if sum(T[i]) >= 6:
        flg = True
    if sum(T[i]) == 4:
        memo.append(i)
if flg:
    print('Yes')
    sys.exit()
if len(memo) == 0:
    print('No')
    sys.exit()
def a(i):
    for k in range(1,N+1):
        if T[i][k] == 1:
            T[i][k],T[k][i] = 0,0
            if sum(T[k])%2 != 0:
                a(k)
            return
a(memo[0])
counta = 1
for c in memo:
    if sum(T[c]) > 0:
        a(c)
        if counta >= 2:
            print('Yes')
            sys.exit()
        counta += 1
print('No')

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import sys
input=sys.stdin.readline

AB = [ list(map(int,input().split())) for _ in range(M)]
conlist = [ [] for _ in range(N)]

for a,b in AB:
    a,b = a-1, b-1
    conlist[a].append(b)
    conlist[b].append(a)


more2 = 0
more2lst = []
degree =[0]*N

for i in range(N):
    cnt = len(conlist[i])

    degree[i] = cnt

    if cnt == 2: continue
    if cnt % 2 == 1: print("No"); exit()
    if cnt > 2:
        more2 += 1
        more2lst.append(cnt)

from collections import deque
from collections import Counter

c = Counter(more2lst)

if more2 == 0: print("No"); exit()

if c[6] > 0:
    print("Yes")
elif c[4] > 2:
    print("Yes")
elif c[4] == 2:

    pathcnt = 0

    _fls = []
    for i in range(N):
        if degree[i] == 4:
            _fls.append(i)
    a,b = _fls

    q = deque([])
    visited = [False]*N

    for e,c in enumerate(conlist[a]):
        q.append(c)
        del conlist[a][e]
        del conlist[c][ conlist[c].index(a) ]

    while q:
        n = q.popleft()
        visited[n] = True

        for c in conlist[n]:
            if  c == a: 
                pass
            elif c == b: 
                pathcnt += 1
                continue
            elif not visited[c] :
                q.append( c )

    if pathcnt == 2:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import sys
input=sys.stdin.readline

AB = [ list(map(int,input().split())) for _ in range(M)]
conlist = [ [] for _ in range(N)]

for a,b in AB:
    a,b = a-1, b-1
    conlist[a].append(b)
    conlist[b].append(a)


more2 = 0
more2lst = []
degree =[0]*N

for i in range(N):
    cnt = len(conlist[i])

    degree[i] = cnt

    if cnt == 2: continue
    if cnt % 2 == 1: print("No"); exit()
    if cnt > 2:
        more2 += 1
        more2lst.append(cnt)

from collections import deque
from collections import Counter

c = Counter(more2lst)

if more2 == 0: print("No"); exit()

if c[6] > 0:
    print("Yes")
elif c[4] > 2:
    print("Yes")
elif c[4] == 2:

    pathcnt = 0

    _fls = []
    for i in range(N):
        if degree[i] == 4:
            _fls.append(i)
    a,b = _fls

    q = deque([])
    visited = [False]*N

    for e,c in enumerate(conlist[a]):
        q.append(c)
        del conlist[a][e]
        del conlist[c][ conlist[c].index(a) ]

    while q:
        n = q.popleft()
        visited[n] = True

        for c in conlist[n]:
            if  c == a:  print("Yes"); exit()
            elif c == b: 
                pathcnt += 1
                continue
            elif not visited[c] :
                q.append( c )

    if pathcnt == 2:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import sys
input=sys.stdin.readline

AB = [ list(map(int,input().split())) for _ in range(M)]
conlist = [ [] for _ in range(N)]

for a,b in AB:
    a,b = a-1, b-1
    conlist[a].append(b)
    conlist[b].append(a)


more2 = 0
more2lst = []
degree =[0]*N

for i in range(N):
    cnt = len(conlist[i])

    degree[i] = cnt

    if cnt == 2: continue
    if cnt % 2 == 1: print("No"); exit()
    if cnt > 2:
        more2 += 1
        more2lst.append(cnt)

from collections import deque
from collections import Counter

c = Counter(more2lst)

if more2 == 0: print("No"); exit()

if c[6] > 0:
    print("Yes")
elif c[4] > 2:
    print("Yes")
elif c[4] == 2:

    _fls = []
    for i in range(N):
        if degree[i] == 4:
            _fls.append(i)
    a,b = _fls

    q = deque([])
    visited = [False]*N

    for e,c in enumerate(conlist[a]):
        q.append(c)
        del conlist[a][e]
        del conlist[c][ conlist[c].index(a) ]

    while q:
        n = q.popleft()
        visited[n] = True

        for c in conlist[n]:
            if  c == a:  print("Yes"); exit()
            elif c == b: continue
            elif not visited[c] :
                q.append( c )

    print("No")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import sys
input=sys.stdin.readline

AB = [ list(map(int,input().split())) for _ in range(M)]
# conn = [ [False]*N for _ in range(N+1)]
conlist = [ [] for _ in range(N)]

for a,b in AB:
    a,b = a-1, b-1
    conlist[a].append(b)
    conlist[b].append(a)


more2 = 0
more2lst = []
more2node = []

degree =[0]*N

for i in range(1, N+1):
    cnt = len(conlist[i-1])

    degree[i-1] = cnt

    if cnt == 2: continue
    if cnt % 2 == 1: print("No"); exit()
    if cnt > 2:
        more2 += 1
        more2lst.append(cnt)
        more2node.append( (cnt, i-1) )

from collections import Counter
c = Counter(more2lst)

from collections import deque

if more2 == 0: print("No"); exit()

if c[6] > 0:
    print("Yes")
elif c[4] > 2:
    print("Yes")
elif c[4] == 2:
    # $BJ,4t(B
    fls = []
    for i in range(N):
        if degree[i] == 4:
            fls.append(i)
    a,b = fls
    # print("a,b: ", a,b)
    q = deque([])
    visited = [False]*N

    for e,c in enumerate(conlist[a]):
        q.append(c)
        del conlist[a][e]
        del conlist[c][ conlist[c].index(a) ]

    while q:
        n = q.popleft()
        # print("n: ", n)
        visited[n] = True
        loop = False

        # print("n: ", n, "conlist: [n]: ", conlist[n])
        # print("visited: ", visited)

        for c in conlist[n]:
            if  c == a:
                # print("loop yes")
                print("Yes")
                exit()
            elif c == b:
                continue
            elif not  visited[c] :
                q.append( c )

    print("No")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import sys
input=sys.stdin.readline

AB = [ list(map(int,input().split())) for _ in range(M)]
# conn = [ [False]*N for _ in range(N+1)]
conlist = [ [] for _ in range(N)]

for a,b in AB:
    a,b = a-1, b-1
    conlist[a].append(b)
    conlist[b].append(a)


more2 = 0
more2lst = []
more2node = []

degree =[0]*N

for i in range(1, N+1):
    cnt = len(conlist[i-1])

    degree[i-1] = cnt

    if cnt == 2: continue
    if cnt % 2 == 1: print("No"); exit()
    if cnt > 2:
        more2 += 1
        more2lst.append(cnt)
        more2node.append( (cnt, i-1) )

from collections import Counter
c = Counter(more2lst)
# print(c)
# exit()

from collections import deque

if more2 == 0: print("No"); exit()

if c[6] > 0:
    print("Yes")
elif c[4] > 2:
    print("Yes")
elif c[4] == 2:
    # $BJ,4t(B
    fls = []
    for i in range(N):
        if degree[i] == 4:
            fls.append(i)

    a,b = fls
    q = deque([a])
    visited = [False]*N
    while q:
        n = q.popleft()
        visited[n] = True

        loop = False
        for c in conlist[n]:
            if not  visited[c] :
                q.append( c )
            if  c == a:
                print("Yes")
                exit()
            if n == b:
                loop=True
                break 
        
        if loop:
            continue
    print("No")
    

else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

v = [0] * n
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    v[a] += 1
    v[b] += 1
    g[a].append(b)
    g[b].append(a)


for i in range(n):
    if v[i] % 2 == 1:
        print("No")
        exit()

v4 = 0
for i in range(n):
    if v[i] >= 6:
        print("Yes")
        exit()
    if v[i] == 4:
        v4 += 1

if v4 == 0:
    print("No")
    exit()
if v4 == 1:
    print("No")
    exit()
if v4 >= 3:
    print("Yes")
    exit()


memo = [0] * n
ord = [0] * n
lowlink = [0] * n
articulation = [0] * n

def dfs(v, p, k):
    memo[v] = 1
    ord[v] = k
    lowlink[v] = ord[v]
    isArticulation = False
    count = 0
    for nv in g[v]:
        if memo[v] == 0:
            count += 1
            dfs(nv, v, k+1)
            lowlink[v] = min(lowlink[v], lowlink[nv])
            if p != -1 and ord[v] <= lowlink[nv]:
                isArticulation = True
        elif nv != p:
            lowlink[v] = min(lowlink[v], ord[nv])

    if p == -1 and count > 1:
        isArticulation = True
    if isArticulation:
        articulation[v] = 1

dfs(0, -1, 0)

count = 0
for i in range(n):
    if v[i] == 4 and articulation[i] == 1:
        count += 1

if count >= 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

v = [0] * n
g = [[] for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    v[a] += 1
    v[b] += 1
    g[a].append(b)
    g[b].append(a)


for i in range(n):
    if v[i] % 2 == 1:
        print("No")
        exit()

v4 = 0
for i in range(n):
    if v[i] >= 6:
        print("Yes")
        exit()
    if v[i] == 4:
        v4 += 1

if v4 == 0:
    print("No")
    exit()
if v4 == 1:
    print("No")
    exit()
if v4 >= 3:
    print("Yes")
    exit()


memo = [0] * n
ord = [0] * n
lowlink = [0] * n
articulation = [0] * n

def dfs(v, p, k):
    memo[v] = 1
    ord[v] = k
    lowlink[v] = ord[v]
    isArticulation = False
    count = 0
    for nv in g[v]:
        if memo[v] == 0:
            count += 1
            dfs(nv, v, k+1)
            lowlink[v] = min(lowlink[v], lowlink[nv])
            if p != -1 and ord[v] <= lowlink[nv]:
                isArticulation = True
        elif nv != p:
            lowlink[v] = min(lowlink[v], ord[nv])

    if p == -1 and count > 1:
        isArticulation = True
    if isArticulation:
        articulation[v] = 1

dfs(0, -1, 0)

count = 0
for i in range(n):
    if v[i] == 4 and articulation[i] == 1:
        count += 1

if count >= 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

x = list(map(int, input().split()))
n=x[0]
m=x[1]
node=[0]*n

for i in range(m):
    y = list(map(int, input().split()))
    node[y[0]-1]+=1
    node[y[1]-1]+=1

a4=0

for i in range(n):
    if node[i]>=6:
        print("Yes")
        sys.exit()

    if node[i]>=4:
        a4+=1
        if a4>=3:
            print("Yes")
            sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:







#ルートを圧縮したい


N,M=input().split(" ")
N=int(N)
M=int(M)
path=[[]for i in range(N)]
for i in range(M):
	a,b=input().split(" ")
	path[int(a)-1].append(int(b)-1)
	path[int(b)-1].append(int(a)-1)



#圧縮
for i in range(len(path)):
	if(len(path[i])==2):
		path[path[i][0]].append(path[i][1])
		path[path[i][1]].append(path[i][0])
		path[path[i][0]].remove(i)
		path[path[i][1]].remove(i)
		path[i]=[]
#odd=0
out=0
#num=0
#for i in path:
#
#
#
#	out+=len(i)
#	if(len(i)%2==1):
#		odd=1
#	if(len(i)!=0):
#		num+=1
#if(out>=6 and odd==0):
#	print("Yes")
#else:
#	print("No")

for i in range(len(path)):
	for j in range(len(path[i])):
		if(path[i][j]==i):
			out+=2
		else:
			out+=1


if(out>=12):
	print("Yes")
else:
	print("No")

#
#print(out)
#for i in range(len(path)):
#	print(i,path[

Submission status: Wrong Answer

Solution code:



#ルートを圧縮したい


N,M=input().split(" ")
N=int(N)
M=int(M)
path=[[]for i in range(N)]
for i in range(M):
	a,b=input().split(" ")
	path[int(a)-1].append(int(b)-1)
	path[int(b)-1].append(int(a)-1)



#圧縮
for i in range(len(path)):
	if(len(path[i])==2):
		path[path[i][0]].append(path[i][1])
		path[path[i][1]].append(path[i][0])
		path[path[i][0]].remove(i)
		path[path[i][1]].remove(i)
		path[i]=[]
odd=0
out=0
for i in path:
	out+=len(i)
	if(len(i)%2==1):
		odd=1

if(out>=12 and odd==0):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [36, 38] or (t%50) < 25) and not (t%50 == 38):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:


#ルートを圧縮したい


N,M=input().split(" ")
N=int(N)
M=int(M)
path=[[]for i in range(N)]
for i in range(M):
	a,b=input().split(" ")
	path[int(a)-1].append(int(b)-1)
	path[int(b)-1].append(int(a)-1)



#圧縮
for i in range(len(path)):
	if(len(path[i])==2):
		path[path[i][0]].append(path[i][1])
		path[path[i][1]].append(path[i][0])
		path[path[i][0]].remove(i)
		path[path[i][1]].remove(i)
		path[i]=[]
odd=0
out=0
for i in path:
	out+=len(i)
	if(len(i)%2==1):
		odd=1

if(out>=6 and odd==0):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 39):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 38):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 36):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 45):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 40):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:





#ルートを圧縮したい


N,M=input().split(" ")
N=int(N)
M=int(M)
path=[[]for i in range(N)]
for i in range(M):
	a,b=input().split(" ")
	path[int(a)-1].append(int(b)-1)
	path[int(b)-1].append(int(a)-1)



#圧縮
for i in range(len(path)):
	if(len(path[i])==2):
		path[path[i][0]].append(path[i][1])
		path[path[i][1]].append(path[i][0])
		path[path[i][0]].remove(i)
		path[path[i][1]].remove(i)
		path[i]=[]
odd=0
out=0
for i in path:
	out+=len(i)
	if(len(i)%2==1):
		odd=1

for i in range(len(path)):
	print(i,path[i])
print(out)
if(out>=6 and odd==0):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 >= 34):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 < 34):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if (t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25) and not (t%50 < 17):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25 or (t%50) > 43:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 25 or (t%50) > 37:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:

N,M=input().split(" ")
N=int(N)
M=int(M)
path=[[]for i in range(N)]
for i in range(M):
	a,b=input().split(" ")
	path[int(a)-1].append(int(b)-1)
	path[int(b)-1].append(int(a)-1)



#圧縮
for i in range(len(path)):
	if(len(path[i])==2):
		path[path[i][0]].append(path[i][1])
		path[path[i][1]].append(path[i][0])
		path[path[i][0]].remove(i)
		path[path[i][1]].remove(i)
		path[i]=[]

out=0
for i in path:
	out+=len(i)




if(out>=6):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = [0] * N
t = 0
for _ in range(M):
    a, b = map(int, input().split())
    X[a-1] += 1
    X[b-1] += 1
    t += a+b
    
for x in X:
    if x % 2 > 0:
        print("No")
        break
else:
    c = 0
    for x in X:
        if x == 4:
            c += 1
        if x >= 6:
            c = 3
            break
    if c >= 3:
        print("Yes")
    elif c == 2:
        if t % 50 in [6, 8, 10, 18, 36, 38] or (t%50) < 37:
            print("No")
        else:
            print("Yes")
    else:
        print("No")