Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import defaultdict

def solve():
    N, M = map(int, input().split())
    F = defaultdict(list)
    D = defaultdict(int)
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1
        F[a] += F[a] + [b]
        F[b] += F[b] + [a]

    E = defaultdict(int)
    X = list()
    for a,d in D.items():
        if d%2==0:
            if d >= 6:
                E[6] += 1
            elif d == 4:
                E[4] += 1
                X.append(a)
            else:
                E[d] += 1
        else:
            E[1] += 1

    if E[1]==0 and (E[6]>=1 or E[4]>=3):
        res = 'Yes'
    elif E[4]==2:
        x, y = X
        q = set((y,))
        R = set((x,))
        while q:
            z = q.pop()
            R.add(z)
            q |= set(F[z])-R
        if set(F[x])&R == set(F[x]):
            res = 'No'
        else:
            res = 'Yes'
    else:
        res = 'No'
    return str(res)
if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-

def solve():
    N, M = map(int, input().split())
    F = [list() for _ in range(N+1)]
    D = [int() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1
        F[a].append(b)
        F[b].append(a)

    E = [0 for _ in range(7)]
    X = list()
    for a,d in enumerate(D[1:], start=1):
        if d%2==0:
            if d >= 6:
                E[6] += 1
            elif d == 4:
                E[4] += 1
                X.append(a)
            else:
                E[d] += 1
        else:
            return 'No'
            E[1] += 1

    if E[6]>0 or E[4]>2:
        return 'Yes'

    elif E[4]<2:
        return 'No'

    else:
        x, y = X
        q = set((y,))
        R = set((x,))
        while q:
            z = q.pop()
            R.add(z)
            q |= set(F[z])-R
        if set(F[x])&R == set(F[x]):
            return 'No'
        else:
            return 'Yes'

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import defaultdict

def solve():
    N, M = map(int, input().split())
    F = defaultdict(list)
    D = defaultdict(int)
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1
        F[a] += F[a] + [b]
        F[b] += F[b] + [a]

    E = defaultdict(int)
    for d in D.values():
        E[d] += 1



    if all(k%2==0 for k in E.keys()) and (sum(E[k] for k in E.keys() if k >=6)>=1 or E[4]>=3):
        res = 'Yes'
    elif E[4]==2:
        x, y = [a for a,d in D.items() if d == 4]
        q = set((y,))
        R = set()
        while q:
            z = q.pop()
            if z != x:
                R.add(z)
                q |= set(F[z])-R
        if set(F[x])&R == set(F[x]):
            res = 'No'
        else:
            res = 'Yes'
    else:
        res = 'No'
    return str(res)
if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-

def solve():
    N, M = map(int, input().split())
    F = [list() for _ in range(N+1)]
    D = [int() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1
        F[a].append(b)
        F[b].append(a)

    E = [0 for _ in range(7)]
    X = list()
    for a,d in enumerate(D[1:], start=1):
        if d%2==0:
            if d >= 6:
                E[6] += 1
            elif d == 4:
                E[4] += 1
                X.append(a)
            else:
                E[d] += 1
        else:
            return 'No'
            E[1] += 1

    if E[6]>0 or E[4]>2:
        return 'Yes'

    elif E[4]<2:
        return 'No'

    else:
        x, y = X
        q = set((y,))
        R = set((x,))
        while q:
            z = q.pop()
            R.add(z)
            q |= set(F[z])-R
        if set(F[x])&R == set(F[x]):
            return 'No'
        else:
            return 'Yes'

if __name__ == '__main__':
    print(solve())