from collections import deque

n=4
m=3
g=[[] for _ in range(n)] 
for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    
def bfs(u, g, n):
    u -= 1
    queue = deque([u])
    d = [-1] * n
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
    return d

d = bfs(1, g, n)
d.sort()
if d[-1]==3:
    print('YES')
else:
    print('NO') from collections import deque n=4 n 4 m=3 m 3 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] g=[[] for _ in range(n)] g [[] for _ in range(n)] for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
     _ range(m) range m a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b g[a-1].append(b-1) [a-1].append [a-1] g a-1 a 1 append b-1 b 1 g[b-1].append(a-1) [b-1].append [b-1] g b-1 b 1 append a-1 a 1 def bfs(u, g, n):
    u -= 1
    queue = deque([u])
    d = [-1] * n
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
    return d bfs u -= 1 u 1 queue = deque([u]) queue deque([u]) deque [u] u d = [-1] * n d [-1] * n [-1] -1 n d[u] = 0 d[u] d u 0 while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
     queue v = queue.popleft() v queue.popleft() queue.popleft queue popleft for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
     i g[v] g v if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
     d[i] is -1 d[i] d i -1 d[i] = d[v] + 1 d[i] d i d[v] + 1 d[v] d v 1 queue.append(i) queue.append queue append i return d d u u g g n n d = bfs(1, g, n) d bfs(1, g, n) bfs 1 g n d.sort() d.sort d sort if d[-1]==3:
    print('YES')
else:
    print('NO') d[-1]==3 d[-1] d -1 3 print('YES') print 'YES' print('NO') print 'NO' m=3 3 m n=4 4 n def bfs(u, g, n):
    u -= 1
    queue = deque([u])
    d = [-1] * n
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
    return d def bfs(u, g, n):
    u -= 1
    queue = deque([u])
    d = [-1] * n
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
    return d bfs d = bfs(1, g, n) bfs(1, g, n) d a,b=map(int,input().split()) map(int,input().split()) a b=map(int,input().split()) map(int,input().split()) b g=[[] for _ in range(n)] [[] for _ in range(n)] g
from collections import deque

n=4
m=3
g=[[] for _ in range(n)] 
for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    
def bfs(u, g, n):
    u -= 1
    queue = deque([u])
    d = [-1] * n
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is -1:
                d[i] = d[v] + 1
                queue.append(i)
    return d

d = bfs(1, g, n)
d.sort()
if d[-1]==3:
    print('YES')
else:
    print('NO')