Problem:


Score : 200 points

Problem Statement

There are four towns, numbered 1,2,3 and 4.
Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.
No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.

Determine if we can visit all the towns by traversing each of the roads exactly once.

Constraints

1 \leq a_i,b_i \leq 4(1\leq i\leq 3)

a_i and b_i are different. (1\leq i\leq 3)

No two roads connect the same pair of towns.

Any town can be reached from any other town using the roads.

Input

Input is given from Standard Input in the following format:

a_1 b_1
a_2 b_2
a_3 b_3

Output

If we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.

Sample Input 1

4 2
1 3
2 3

Sample Output 1

YES

We can visit all the towns in the order 1,3,2,4.

Sample Input 2

3 2
2 4
1 2

Sample Output 2

NO

Sample Input 3

2 1
3 2
4 3

Sample Output 3

YES



Sample input:
4 2
1 3
2 3


Sample output:
YES

Submission status: Accepted

Solution code:
ab = []
for i in range(3):
  p, q = map(int, input().split())
  ab.append(p)
  ab.append(q)
o, d = 0, 0
count = 0
for i in range(1, 5):
  if ab.count(i) == 2 or ab.count(i) == 1:
    count += 1
if count == 4:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
from collections import deque

def bfs():
    q = deque()
    t = 0
    x = [-1 + i for i in range(5)]
    for i in range(1, 5):
        q.append(i)
        dist = [-1] * 5
        dist[i] = 0
        while q:
            j = q.popleft()
            for i in G[j]:
                if dist[i] == -1:
                    dist[i] = dist[j] + 1
                    q.append(i)
        dist.sort()
        if x == dist:
            t = 1
            break
    return t

G = [[] for _ in range(5)]
for _ in range(3):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
print("YES" if bfs() else "NO")

Submission status: Accepted

Solution code:
cnt = [0 for i in range(4)]
for i in range(3):
    a, b = map(int, input().split())
    cnt[a - 1] += 1
    cnt[b - 1] += 1
if sorted(cnt) == [1, 1, 2, 2]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
from collections import defaultdict
dic1 = defaultdict(int)
for i in range(3):
    n,m = map(int,readline().split())
    dic1[n] += 1
    dic1[m] += 1

lst1 = list(dic1.values())
lst1.sort()

if lst1 == [1,1,2,2]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
lst=[a,b,c,d,e,f]
ans='NO'
if lst.count(1)==1:
  if lst.count(2)==2:
    if lst.count(3)==2:
      if lst.count(4)==1:
        ans='YES'
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    count = [0, 0, 0, 0]
    for _ in range(3):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        count[a] += 1
        count[b] += 1

    if count.count(1) == 2 and count.count(2) == 2:
        ans = "YES"
    else:
        ans = "NO"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    d = defaultdict(int)
    for _ in range(3):
        a, b = list(map(int, input().split()))
        d[a] += 1
        d[b] += 1
    if sorted(d.values()) == [1, 1, 2, 2]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
a = list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))

for i in [1, 2, 3, 4]:
    if 1 <= a.count(i) <= 2:
        continue
    else:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
l = [list(map(int,input().split())) for i in range(3)]
a,b = [list(i) for i in zip(*l)]
t = [0] * 4

for i in range(3):
    t[a[i] - 1] += 1
    t[b[i] - 1] += 1

if max(t) == 3:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
T = [0 for _ in range(4)]
for i in range(3):
    a, b = map(int, input().split())
    T[a - 1] += 1
    T[b - 1] += 1
if max(T) == 3:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
temp=[a1,a2,a3,b1,b2,b3]
t1=temp.count(1)
t2=temp.count(2)
t3=temp.count(3)
t4=temp.count(4)
if max(t1,t2,t3,t4)==2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
G = [0] * 4
for i in range(3):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a] += 1
    G[b] += 1

for i in range(4):
    if G[i] == 3:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
C=[0]*4
for _ in range(3):
    a,b=map(int,input().split())
    C[a-1]+=1
    C[b-1]+=1
print('YNEOS'[any(c>2 for c in C)::2])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    cnt=[0]*5
    for _ in range(3):
        a,b=MI()
        cnt[a]+=1
        cnt[b]+=1
    for c in cnt:
        if c>2:
            print("NO")
            exit()
    print("YES")

main()

Submission status: Accepted

Solution code:
road = [0]*4
for i in range(3):
  a,b = map(int,input().split())
  road[a-1]+=1
  road[b-1]+=1
if max(road)>=3:
  print('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
from collections import Counter
import sys
A = []
for i in range(3):
    a,b = map(int,input().split())
    A.append(a)
    A.append(b)
c = Counter(A)
for i in c.values():
    if i >=3:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
ab=[list(map(int, input().split())) for _ in range(3)]
ab=sum(ab,[])
if ab.count(1)>=3 or ab.count(2)>=3 or ab.count(3)>=3 or ab.count(4)>=3:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    ab = [list(map(int, input().split())) for _ in range(3)]
    count = [0] * 4
    for a, b in ab:
        count[a - 1] += 1
        count[b - 1] += 1
    if count.count(3) >= 1:
        print('NO')
    else:
        print("YES")


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
ab = [0 for _ in range(4)]
for _ in range(3):
    a, b = map(int, input().split())
    ab[a - 1] += 1
    ab[b - 1] += 1
if ab.count(1) == 2 and ab.count(2) == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import Counter
lst = []
for i in range(3):
  a, b = map(int, input().split())
  lst.append(a)
  lst.append(b)
if sorted(list(Counter(lst).values())) == [1, 1, 2, 2]:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
root = [[] for i in range(4)]
for _ in range(3):
    a,b = map(int,input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)

visited = [False] * 4
visited[0] = True

def dfs(s):
    if all(visited):
        print('YES')
        exit()

    for i in root[s]:
        if visited[i]:
            continue

        visited[i] = True
        dfs(i)
        visited[i] = False

dfs(0)
print('NO')

Submission status: Accepted

Solution code:
r = [0]*4

for i in range(3):
    a,b = map(int,input().split())
    r[a-1]+=1
    r[b-1]+=1
if r.count(2) == 2 and r.count(1) == 2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a1 = l()
a2 = l()
a3 = l()
AB = a1+a2+a3
c = Counter(AB)
if 1 in AB and 2 in AB and 3 in AB and 4 in AB and list(reversed(sorted(list(c.values()))))[0] == 2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import chain
from sys import stdin
d = Counter(chain.from_iterable([list(map(int, stdin.readline().rstrip().split())) for _ in range(3)]))
if d[1] <= 2 and d[2] <= 2 and d[3] <= 2 and d[4] <= 2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
miti = [[] for _ in range(5)]

for i in range(3):
    a, b = map(int, input().split())
    miti[a].append(b)
    miti[b].append(a)

cnt_list = []

for m in miti:
    cnt_list.append(len(m))
cnt_list.sort()
if cnt_list == [0, 1, 1, 2, 2]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

ab=[list(map(int,input().split())) for i in range(3)]
lst=[0]*4
for i in range(3):
    a,b=ab[i]
    lst[a-1]+=1
    lst[b-1]+=1

for i in range(4):
    if lst[i]==0 or lst[i]==3:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
l = [0]*5
for i in range(3):
  a,b = map(int,input().split())
  l[a]+=1
  l[b]+=1
if max(l) == 3:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
def resolve():
    a = []
    b = []
    for i in range(3):
        A, B = map(int, input().split())
        a.append(A)
        a.append(B)
    for j in range(1, 5):
        b.append(a.count(j))
    if b.count(2) == 2 and b.count(1) == 2:
        print("YES")
    else:
        print("NO")
resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)

for i in range(3):
    p,q = map(int,input().split())
    dic[p] += 1
    dic[q] += 1
#print(dic)
L = []
for v in dic.values():
    L.append(v)

odd = [x%2 ==1 for x in L]
even = [x%2 ==0 for x in L]

if sum(odd) == 2 or sum(even) == 4:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
d = {1:0, 2:0, 3:0, 4:0}
for i in range(3):
  a, b = map(int, input().split())
  d[a] += 1
  d[b] += 1
d = sorted(d.items(), key=lambda x:x[1])
if len(d) == 4 and d[0][1] == 1 and d[1][1] == 1 and d[2][1] == 2 and d[3][1] == 2:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
t=sorted(map(int,open(0).read().split()))
print(['YES','NO'][max([t.count(i)for i in range(1,5)])>2])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

dim = [0]*4

for _ in range(3):
	a, b = MAP()
	dim[a-1] += 1
	dim[b-1] += 1

c = Counter(dim)

if c[1] == 2 and c[2] == 2:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

a = []
for _ in range(3):
	a.extend(LIST())

C = sorted(Counter(a).values())

print("YES" if C == [1, 1, 2, 2] else "NO")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

dic = DD(int)
for _ in range(3):
  a,b = IL()
  dic[a] += 1
  dic[b] += 1
  
if max(dic[k] for k in dic)<=2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
l = []
for i in range(3):
  a,b = map(int, input().split())
  l.append(a)
  l.append(b)

for i in range(1,5):
  cnt=0
  for itm in l:
    if i==itm:
      cnt+=1
  if cnt>=3:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
import collections
import itertools

li = [list(map(int,input().split())) for i in range(3)]
li = list(itertools.chain.from_iterable(li))
li.sort()

c = list(collections.Counter(li).values())

if c.count(2) == 2 and c.count(1) == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import deque
S = [list(map(int, input().split())) for _ in range(3)]

l=[0,0,0,0]

for i in range(3):
    for j in range(2):
        l[S[i][j]-1]+=1
#print(l)
if max(l)==3:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
a1,b1=input().split()
a2,b2=input().split()
a3,b3=input().split()
lista=[a1,a2,a3,b1,b2,b3]
yn=0
for i in range(1,5):
    if lista.count(str(i))==0 or lista.count(str(i))>2:
        yn=1
        break
if yn==1:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]


# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    count =[0]*4
    for i in range(3):
       a,b = map(int, input().split())
       count[a-1]+=1
       count[b-1]+=1
    flag = True
    for i in count:
        if i ==3:
            flag=False
    if flag:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=4
es=[[] for i in range(n)]
for i in range(n-1):
   a,b=map(int,input().split())
   es[a-1].append(b-1)
   es[b-1].append(a-1)
use=sorted([len(es[i]) for i in range(4)])

print("YES" if use==[1,1,2,2] else "NO")

Submission status: Accepted

Solution code:
# AB = [list(map(int, input().split())) for i in range(3)]

paths = [[] for _ in range(4)]
for _ in range(3):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    paths[a].append(b)
    paths[b].append(a)

start = 0
for i in range(4):
    if len(paths[i]) == 1:
        start = i
        break

visited = {start}
def dfs(n):
    if len(paths[n]) >= 3:
        print('NO')
        exit()
    for p in paths[n]:
        if p in visited:
            continue
        visited.add(p)
        dfs(p)

dfs(start)

if len(visited) == 4:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
node = set([1,2,3,4])
for _ in range(3):
  a,b = map(int,input().split())
  node = node.intersection(set([a,b]))
  
print('NO' if len(node) else 'YES')

Submission status: Accepted

Solution code:
def resolve():
    s=[0,0,0,0]
    for i in range(3):
        a,b = map(lambda x: int(x)-1,input().split())
        s[a]+=1
        s[b]+=1
    for i in s:
        if i==3:
            print("NO")
            return
    print("YES")

resolve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    tree = [[] for _ in range(4)]
    for _ in range(3):
        a, b = map(int, input().split())
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    def dfs(v, p):
        for u in tree[v]:
            if u == p:
                continue
            elif visited[u]:
                return
            else:
                visited[u] = True
                dfs(u, v)
                return

    visited = [False] * 4
    visited[0] = True
    dfs(0, -1)
    print("YES" if visited.count(True) == 4 else "NO")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
abl = [map(int,input().split()) for nesya in range(3)]
s = [1,1,2,2,3,3,4,4]
c = 0
for ab in abl:
  for n in ab:
    if n in s:
      s.remove(n)
    else:
      c += 1
if c == 0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
from collections import defaultdict,deque

N = 4
d = defaultdict(list)
for i in range(3):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)


for i in range(1,5):
    dist = [None]*N
    q = deque()
    s = i  # スタート
    q.append(s)
    dist[s-1] = 0

    while len(q)!=0:
        From = q.popleft()
        for To in d[From]:
            if dist[To-1] == None:
                q.append(To)
                dist[To-1] = dist[From-1]+1
    if set(dist)=={0,1,2,3}:
        print("YES")
        exit()
print("NO")

Submission status: Accepted

Solution code:
import collections
a, b = map(int, input().split())
c, d = map(int, input().split())
e, f = map(int, input().split())
arr = [a,b,c,d,e,f]
A = collections.Counter(arr).most_common()

if len(A) == 4:
    if A[0][1] == 2 and A[1][1] == 2 and A[2][1] == 1 and A[3][1] == 1:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

Submission status: Accepted

Solution code:
from collections import defaultdict
cnt = defaultdict(int)
for i in range(3):
    a, b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1

print("YES" if max(cnt.values()) == 2 and min(cnt.values()) == 1 else "NO")

Submission status: Accepted

Solution code:
city = [0]*4
for i in range(3):
    a,b = map(int,input().split())
    city[a-1] += 1
    city[b-1] += 1
if city.count(3) == 1:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
c=[0]*5
for i in range(3):
  a,b=map(int,input().split())
  c[a]+=1
  c[b]+=1
if 3 in c:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    vec = [0]*4
    for x in range(3):
        A,B = map(int, input().split())
        A -= 1
        B -=1
        vec[A] += 1
        vec[B] += 1
    
    if(vec[0] == 1 and vec[1] == 2 and vec[2] == 2 and vec[3] == 1):
        print("YES")
    else:
        print("NO")



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = 3
num_list = [list(map(int, input().split())) for _ in range(n)]
N = (sum(num_list, []))
N1 = N.count(1)
N2 = N.count(2)
N3 = N.count(3)
N4= N.count(4)
if N1 > 2 or N2 > 2 or N3 > 2 or N3 > 2 or N4 > 2:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
# coding: utf-8
L=[0 for i in range(4)]

for i in range(3):
    a,b=map(int,input().split())
    L[a-1]+=1
    L[b-1]+=1

cnt1=0
cnt2=0

for i in range(4):
    if L[i]==1:
        cnt1+=1
    elif L[i]==2:
        cnt2+=1

if cnt1==cnt2==2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
A = list(map(int,(input().split())))
S1 = set(A)
S2 = set(A)
for i in range(2):
    B = list(map(int,input().split()))
    S1 = S1 | set(B)
    S2 = S2 & set(B)
if len(S1) == 4 and len(S2) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import collections
a1,b1 = list(map(int,input().split()))
a2,b2 = list(map(int,input().split()))
a3,b3 = list(map(int,input().split()))
dd = collections.defaultdict(int)
dd[a1] += 1
dd[a2] += 1
dd[a3] += 1
dd[b1] += 1
dd[b2] += 1
dd[b3] += 1
for i in dd.values():
    if i > 2:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
li = []
for _ in range(3):
    li += list(map(int, input().split()))

mx = 0
for i in range(1, 5):
    mx = max(mx, li.count(i))

if mx == 3:
    ans = "NO"
else:
    ans = "YES"

print(ans)

Submission status: Accepted

Solution code:
listA=[]
import collections 
for i in range(3):
    B = list(map(int,input().split()))
    listA.append(B[0])
    listA.append(B[1])
listA=collections.Counter(listA)
listA = listA.most_common()
if listA[0][1] == 2 and listA[1][1] == 2 and listA[2][1] == 1 and listA[3][1] == 1:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
L = []
for _ in range(3):
  A,B = map(int,input().split()) 
  L.append(A)
  L.append(B)
L.sort()
M = []
a = L.count(1)
b = L.count(2)
c = L.count(3)
d = L.count(4)
M.append(a)
M.append(b)
M.append(c)
M.append(d)
M.sort()
if M == [1,1,2,2]:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

a, b = map(int, input().split())
c, d = map(int, input().split())
e, f = map(int, input().split())

abcdef = [a,b,c,d,e,f]

from collections import Counter

cc = Counter(abcdef)

ccm = cc.most_common()

if ccm[0][1]==2 and ccm[1][1]==2 and ccm[2][1]==1 and ccm[3][1]==1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
a=[0]*3
b=[0]*3

a[0],b[0]=map(int,input().split())
a[1],b[1]=map(int,input().split())
a[2],b[2]=map(int,input().split())

d=dict()
c=a+b
for i in c:
  if i not in d:
    d[i]=1
  else:
    d[i]+=1

mini=100
maxi=0
for j in d:
  mini=min(mini,d[j])
  maxi=max(maxi,d[j])


if mini==1 and maxi==2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
li=[0]*4
for i in range(3):
    a,b=map(int,input().split())
    li[a-1]+=1
    li[b-1]+=1
    
if li.count(1)==2 and li.count(2)==2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
# a-b-c-dのようなつながり方でないとアウト
connected_town_dict = {i:set() for i in range(1,5)}

for i in range(3):
    a,b = map(int, input().split())
    connected_town_dict[a].add(b)
    connected_town_dict[b].add(a)

for i in range(1,5):
    if len(connected_town_dict[i])!=1 and len(connected_town_dict[i])!=2:
         print("NO")
         break
else:
    print("YES")

Submission status: Accepted

Solution code:
l=[0]*4
for i in range(3):
    N,M=map(int,input().split())
    l[N-1]+=1
    l[M-1]+=1
print("YES" if max(l)<3 else "NO")

Submission status: Accepted

Solution code:
ab = [list(map(int, input().split())) for _ in range(3)]
road = [0] * 4
for a, b in ab:
    road[a-1] += 1
    road[b-1] += 1
road.sort()
if road[0]==road[1] and road[2]==road[3]: print("YES")
else: print("NO")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

a1, b1 = map(int, readline().split())
a2, b2 = map(int, readline().split())
a3, b3 = map(int, readline().split())
counter = sorted(list(Counter([a1, a2, a3, b1, b2, b3]).values()))
if counter == [1, 1, 2, 2]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
count_list = [0,0,0,0]
for i in range(3):
  dis = [int(i) for i in input().split()]
  for j in dis:
    count_list[j-1] += 1

if max(count_list) >= 3:
  print('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
arr = list(map(int, input().split()))
flg = 0
for i in range(2):
  a,b = map(int, input().split())
  if arr[0] == a:
    arr.insert(0,b)
  elif arr[0] == b:
    arr.insert(0,a)
  elif arr[-1] == a:
    arr.append(b)
  elif arr[-1] == b:
    arr.append(a)
  elif i == 0:
    flg = 1
if len(arr) == 4 or flg == 1:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
from collections import*
print("YNEOS"[Counter(open(0).read().split()).most_common()[0][1]==3::2])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

# B - Path
route = []

for i in range(3):
	a, b = map(int, input().split())	
	route.append(a)
	route.append(b)

count = 0

for i in range(1, 5):
	if route.count(i) >= 2:
		count += 1

if count >= 2:
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

route =[0]*4
for i in range(3):
    a,b=mii()
    route[a-1]+=1
    route[b-1]+=1

cou = Counter(route)

ans1=0
ans2=0
for i in route:
    if i==1:
        ans1+=1
    elif i==2:
        ans2+=1

if ans1==2 and ans2==2:
    print("YES")
else:
    print("NO")