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:
graph = [[]for _ in range(4)]
for i in range(3):
    a,b = map(int,input().split())
    a-= 1
    b-= 1
    graph[a].append(b)
    graph[b].append(a)
maxa = 0
for i in range(4):
    maxa = max(len(graph[i]),maxa)

if maxa == 3:
    print("NO")
    exit(0)
print("YES")

Submission status: Accepted

Solution code:
import sys
from collections import Counter
ct = {i:0 for i in range(1,5)}
for i in range(3):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    ct[a] += 1
    ct[b] += 1
ct2 = Counter(ct.values())
if ct2[1] == 2 and ct2[2] == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
G = {i:[] for i in range(1,5)}
for _ in range(3):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
cnt = 0
for x in G:
    if len(G[x])%2==1:
        cnt += 1
if cnt>2:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lista = []
for i in range(3):
  a,b = map(int,input().split())
  lista.append(a)
  lista.append(b)
l1 = 0
l2 = 0
l3 = 0
l4 = 0
for j in lista:
  if j == 1:
    l1 += 1
  if j == 2:
    l2 += 1
  if j == 3:
    l3 += 1
  if j == 4:
    l4 += 1
c = (l1)%2 + (l2)%2 + (l3)%2 + (l4)%2
if c <= 2:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    ls = []
    for i in range(3):
        a, b = list(map(int, input().rstrip('\n').split()))
        ls.append(a)
        ls.append(b)
    ls = collections.Counter(ls).most_common()
    print("YES" if ls[0][1] == 2 and ls[1][1] == 2 and ls[2][1] == 1 and ls[3][1] == 1 else "NO")


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s={1,2,3,4}
for i in range(3):
    s&=set(map(int,input().split()))
print('YES' if not s else 'NO')

Submission status: Accepted

Solution code:
# 2019/11/27

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

odd=0
for c in edge:
    if len(c)%2:odd+=1
print('YES' if odd==2 else 'NO')

Submission status: Accepted

Solution code:
A = [0]*5
for _ in range(3):
  a, b = map(int, input().split())
  A[a] += 1
  A[b] += 1

if max(A) < 3:
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(a: "List[int]", b: "List[int]"):
    ab = a+b
    t1 = [ab.count(1), ab.count(2), ab.count(3), ab.count(4)]
    
    if t1.count(1) == t1.count(2):
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = [int()] * (3)  # type: "List[int]"
    b = [int()] * (3)  # type: "List[int]"
    for i in range(3):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = 0
for i in range(1,5):
  tmp = 0
  for j in range(3):
    tmp += a[j].count(i) 
  if tmp == 2:
    cnt += 1

if cnt == 2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
abs = []
for i in range(3):
    ab = list(map(int, input().split()))
    abs.extend(ab)
c = Counter(abs)
if c.most_common(1)[0][1] <= 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


AB = [list(map(int, sys.stdin.readline().split())) for _ in range(3)]

graph = [[] for _ in range(5)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

ok = False
for a, b, c, d in itertools.permutations(range(1, 5)):
    ok |= b in graph[a] and c in graph[b] and d in graph[c]
if ok:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random

import os
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    a1, b1 = inputMap()
    a2, b2 = inputMap()
    a3, b3 = inputMap()
    
    maps = {}
    maps[a1] = 1
    maps[b1] = 1
    
    if a2 in maps:
        maps[a2] += 1
    else:
        maps[a2] = 1
        
    if b2 in maps:
        maps[b2] += 1
    else:
        maps[b2] = 1
        
    if a3 in maps:
        maps[a3] += 1
    else:
        maps[a3] = 1
        
    if b3 in maps:
        maps[b3] += 1
    else:
        maps[b3] = 1
        
    for k,v in maps.items():
        if v > 2:
            print("NO")
            sys.exit()
            
    print("YES")
    
    
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())
cnt = [0,0,0,0]
cnt[a1-1] += 1
cnt[a2-1] += 1
cnt[a3-1] += 1
cnt[b1-1] += 1
cnt[b2-1] += 1
cnt[b3-1] += 1
print("YES" if max(cnt) < 3 else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

city = [list(map(int,input().split())) for _ in range(3)]

li = []

for i in range(3):
    for j in range(2):
        li.append(city[i][j])
        
c = Counter(li)

for i in range(1,5):
    if c[i] >= 3:
        print("NO")
        exit()
        
print("YES")

Submission status: Accepted

Solution code:
c = [0]*4

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

if sorted(c) == [1, 1, 2, 2]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

z = []
for i in range(3):
    a,b = inpl()
    z.append(a)
    z.append(b)
c = Counter(z)
for key in c.keys():
    if c[key] > 2:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
t = [0, 0, 0, 0]

for i in range(3):
    a, b = map(int, input().split())
    t[a - 1] += 1
    t[b - 1] += 1
print("NO" if 3 in t else "YES")

Submission status: Accepted

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

tmp=[]
for a,b in AB:
  tmp.append(a)
  tmp.append(b)
for i in set(tmp):
  if tmp.count(i)==3:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
x=[]
b2=0
b3=0
b1=0
b4=0
a1=input().split()
a1[0]=int(a1[0])
a1[1]=int(a1[1])
a2=input().split()
a2[0]=int(a2[0])
a2[1]=int(a2[1])
a3=input().split()
a3[0]=int(a3[0])
a3[1]=int(a3[1])
x.append(a1[0])
x.append(a1[1])
x.append(a2[0])
x.append(a2[1])
x.append(a3[0])
x.append(a3[1])
for i in range(6):
    if x[i]==1:
        b1+=1
    elif x[i]==2:
        b2+=1
    elif x[i]==3:
        b3+=1
    else:
        b4+=1
if b2==2 and b3==2:
    print('YES')
elif b1==2 and b2==2:
    print('YES')
elif b1==2 and b3==2:
    print('YES')
elif b1==2 and b4==2:
    print('YES')
elif b4==2 and b3==2:
    print('YES')
elif b2==2 and b4==2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

cnt=[0,0,0,0]

for i in range(0,3):
    for j in range(0,2):
        cnt[path[i][j]-1]+=1

if cnt[0]<3 and cnt[1]<3 and cnt[2]<3 and cnt[3]<3:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X=[0]*4
for i in range(3):
  A,B=map(int,input().split())
  X[A-1]+=1
  X[B-1]+=1
X.sort()
if(X[0]==1 and X[1]==1 and X[2]==2):
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
import sys

city = [0] * 4
for i in range(3):
    a, b = list(map(int, input().split()))
    city[a - 1] += 1
    city[b - 1] += 1
odd_count = 0
for count in city:
    if count % 2 == 1:
        odd_count += 1
        if odd_count > 2:
            print("NO")
            sys.exit()
print("YES")

Submission status: Accepted

Solution code:
l=[list(map(int, input().split())) for i in range(3)]
r=[0,0,0,0]
for i in range(3):
    r[l[i][0]-1]+=1
    r[l[i][1]-1]+=1
r.sort()
if r==[1,1,2,2]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
n1=n2=n3=n4=0
for _ in range(3):
    a,b = map(int,input().split())
    if a==1:
        n1+=1
    elif a==2:
        n2+=1
    elif a==3:
        n3+=1
    else:
        n4+=1
    if b==1:
        n1+=1
    elif b==2:
        n2+=1
    elif b==3:
        n3+=1
    else:
        n4+=1
if n1*n2*n3*n4==4:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
I=input;s=I()+I()+I();print("YNEOS"[any(s.count(x)>2for x in"1234")::2])

Submission status: Accepted

Solution code:
l = [0, 0, 0, 0]

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

for i in l:
    if i == 0 or i >= 3:
        print("NO")
        exit()

print("YES")

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 cnt.count(2) == 2 and cnt.count(1) == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
#%%
a = [0] * 3
b = [0] * 3
c = []
d = [0] * 3

for i in range(3):
    a[i], b[i] = map(int, input().split())
    c.append(a[i])
    c.append(b[i])
    d[i] = ''.join(str(a[i])+str(b[i]))
    if a[i] == b[i] :
        flag = False

flag = True

if 1 <= c.count(1) <= 2 and 1 <= c.count(2) <= 2 and 1 <= c.count(3) <= 2 and 1 <= c.count(4) <= 2:
     pass
else:
    flag = False

if len(list(set(d))) == 3:
    pass
else:
    flag = False

if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
cnt = [0] * 4
for _ in range(3):
    a, b = tuple(map(int, input().split()))
    cnt[a-1] += 1
    cnt[b-1] += 1
for c in cnt:
    if c >= 3:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
 #B-Path
a1,b1=map(int,input().split( ))
a2,b2=map(int,input().split( ))
a3,b3=map(int,input().split( ))
x=[a1,b1,a2,b2,a3,b3]
y=[x.count(i) for i in range(1,5)]
if max(y)==3 or min(y)==0:
    print("NO")

else:
    print("YES")

Submission status: Accepted

Solution code:
ans=[0]*4

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

f1=0
f2=0
for i in range(4):
    if ans[i]==1:
        f1+=1
    if ans[i]==2:
        f2+=1
if f1==2 and f2==2:
    print('YES')
else:
    print('NO')

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
#print(L)

print("NO" if max(L)==3 else "YES")

Submission status: Accepted

Solution code:
from collections import defaultdict


def resolve():
    d = defaultdict(int)
    ab = list(list(map(int, input().split())) for _ in range(3))
    for a, b in ab:
        d[a] += 1
        d[b] += 1
    print("YES" if set(d.keys()) == {1, 2, 3, 4} and all(v < 3 for v in d.values()) else "NO")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# yahoo-procon2019-qualB - Path
def main():
    *A, = map(int, open(0).read().split())
    cnt = [0] * 5
    for i in A:
        cnt[i] += 1
    flg = all(i < 3 for i in cnt[1:])
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# yahoo-procon2019-qualB - Path
def main():
    *A, = map(int, open(0).read().split())
    cnt = [0] * 5
    for i in A:
        cnt[i] += 1
    flg = all(0 < i < 3 for i in cnt[1:])
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
E = [set() for i in range(4)]
for i in range(3):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
ok = True
for i in range(4):
  if len(E[i]) >= 3:
    ok = False
    break
if ok:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
def main():

    count = dict()
    for _ in range(3):
        a, b = map(int, input().split())
        count[a] = count.get(a, 0) + 1
        count[b] = count.get(b, 0) + 1
    if sorted(count.values()) == [1, 1, 2, 2]:
        return "YES"
    return "NO"


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

Submission status: Accepted

Solution code:
a=[0]*4
for i in range(3):
	x,y=map(int,input().split())
	a[x-1]+=1
	a[y-1]+=1
c=0
for i in range(4):
	if a[i]%2!=0:
		c+=1
if c==0 or c==2:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
d={}
for k in map(int,open(0).read().split()):d[k]=d.get(k,0)+1
for v in d.values():
 if v>2:print("NO");quit()
print("YES")

Submission status: Accepted

Solution code:
ab = [list(map(int, input().split())) for _ in range(3)]
dict_ab = {}

for i in range(3):
    if ab[i][0] not in dict_ab:
        dict_ab[ab[i][0]] = 1
    else:
        dict_ab[ab[i][0]] += 1
    if ab[i][1] not in dict_ab:
        dict_ab[ab[i][1]] = 1
    else:
        dict_ab[ab[i][1]] += 1

if min(dict_ab.values()) == 1 and max(dict_ab.values()) == 2:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
x = Counter()
for _ in range(3):
    a,b = input().split()
    x[a] += 1
    x[b] += 1
if len(x) == 4 and max(x.values()) != 3:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans_list = [0]*4

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

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

Submission status: Accepted

Solution code:
AB = [list(map(int,input().split())) for _ in [0]*3]

E = [[] for _ in [0]*4]
for a,b in AB:
    a-=1
    b-=1
    E[a].append(b)
    E[b].append(a)

i = 0
for _ in [0]*2:
    d = [-1]*4
    d[i] = 0
    q = [i]
    while q:
        i = q.pop()
        for j in E[i]:
            if d[j]!= -1 : continue
            d[j] = d[i]+1
            q.append(j)
print("YES" if max(d)==3 else "NO")

Submission status: Accepted

Solution code:
def solve(a, b):
    v = [0,0,0,0]
    for i in range(3):
        v[a[i]-1] += 1
        v[b[i]-1] += 1
    return "YES" if sorted(v) == [1,1,2,2] else "NO"

a = [0]*3
b = [0]*3
for i in range(3):
    a[i], b[i] = map(int, input().split())
print(solve(a, b))

Submission status: Accepted

Solution code:
import collections


def main():
    routeList = [list(map(int,input().split())) for _ in range(3)]
    routeList = [i for inner in routeList for i in inner]
    ansList = collections.Counter(routeList)
    
    for i in ansList:
        if ansList[i] == 3:
            print("NO")
            exit()
    print('YES')
    

    


if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
g=[0]*5
import sys
input=sys.stdin.readline
for _ in range(3):
    a,b=map(int,input().split())
    g[a]+=1
    g[b]+=1
if g.count(1)==2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from fractions import Fraction

c = [0]*4
for i in range(3):
    a, b = map(int, input().split())
    c[a-1] += 1
    c[b-1] += 1
for i in range(4):
    if c[i] > 2:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

if s.count(2)==2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
X = [0 for _ in range(4)]

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

if max(X) > 2:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
lst = [0] * 5
for _ in range(3):
    a, b = map(int, input().split())
    lst[a] += 1
    lst[b] += 1

if lst.count(2) == 2:
    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
print("YNEOS"[d[1]==3or d[2]==3or d[3]==3or d[4]==3::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
x = []
for i in range(3):
    p, q = map(int, input().split())
    x.append(p)
    x.append(q)
ans = []
for i in range(4):
    ans.append(x.count(i + 1))
ans.sort()
if ans == [1, 1, 2, 2]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(4):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                if i != j and j != k and k != l and l != i and i != k and j != l:
                    if j in G[i] and k in G[j] and l in G[k]:
                        print("YES")
                        exit()
print("NO")

Submission status: Accepted

Solution code:
r=[]
for i in range(3):
  a,b=map(int,input().split())
  r.append(a);r.append(b)
print("YES" if r.count(1) <=2 and r.count(2) <=2 and r.count(3)<=2 and r.count(4) <=2 else "NO")

Submission status: Accepted

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

g = [[] for _ in range(4)]
for a, b in AB:
	a, b = a - 1, b - 1
	g[a] += [b]
	g[b] += [a]

def dfs(v, p, visited=None):
	if None == visited:
		visited = [False] * 4
	visited[v] = True
	for n in g[v]:
		if visited[n]:
			continue
		if n == p:
			continue
		return dfs(n, v, visited)
	return all(visited)

#print([dfs(x, -1) for x in range(4)])
print(["YES", "NO"][not(any([dfs(x, -1) for x in range(4)]))])

Submission status: Accepted

Solution code:
li = [0,0,0,0]

for i in range(3):
    a,b = map(int,input().split())
    for j in range(1,5):
        if(a == j or b == j):
            li[j-1] += 1;

if(min(li) == 0 or max(li) == 3):
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
cnt = [0, 0, 0, 0]

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


def solve():
    odd = 0
    for c in cnt:
        if c == 0:
            return False
        elif c == 1:
            odd += 1

    return odd == 2


print('YES' if solve() else 'NO')

Submission status: Accepted

Solution code:
# yahoo-procon2019-qualB - Path
import sys
input = sys.stdin.readline

def main():
    C = [0] * 4
    for _ in range(3):
        a, b = map(int, input().split())
        C[a - 1] += 1
        C[b - 1] += 1
    print("YES" if set(C) == {1, 2} else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# yahoo-procon2019-qualB - Path
def main():
    C = [0] * 4
    for _ in range(3):
        a, b = list(map(int, input().rstrip().split()))
        C[a - 1] += 1
        C[b - 1] += 1
    print("YES" if set(C) == {1, 2} else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# yahoo-procon2019-qualB - Path
from collections import Counter
from itertools import chain


def main():
    P = [list(map(int, input().rstrip().split())) for _ in range(3)]
    C = Counter(chain.from_iterable(P)).most_common()
    c = [i[1] for i in C]
    print("YES" if c == [2, 2, 1, 1] else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    a = [0 for i in range(5)]

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

    flg = 1
    odd_flg = 0
    for i in range(1, 5):
        if a[i] == 0:
            flg = 0
        if a[i] % 2 == 1:
            odd_flg += 1

    if odd_flg > 2:
        flg = 0

    if flg:
        print('YES')
    else:
        print('NO')





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = [0, 0, 0, 0]
for i in range(3):
	x = list(map(int, input().split()))
	for xi in x:
		ans[xi - 1] += 1
if sorted(ans) == [1, 1, 2, 2]:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
from collections import Counter

E = []
for _ in range(3):
    a, b = map(int, input().split())
    E.append(a); E.append(b)
cnt = Counter(E)
print('YES' if max(cnt.values()) == 2 else 'NO')

Submission status: Accepted

Solution code:
from itertools import permutations

ways = [tuple(map(int, input().split())) for _ in range(3)]
for p in permutations(ways, 3):
    path1 = [p[0][0], p[0][1]]; path2 = [p[0][1], p[0][0]]
    for i in range(1, 3):
        if path1[-1] in p[i]:
            a, b = p[i]; path1.append(a if path1[-1] == b else b)
        if path2[-1] in p[i]:
            a, b = p[i]; path2.append(a if path2[-1] == b else b)
    if max(len(path1), len(path2)) == 4: print('YES'); break;
else: print('NO')

Submission status: Accepted

Solution code:
Inp1 = list(input().split())
Inp1.extend(input().replace(' ',''))
Inp1.extend(input().replace(' ',''))

Inp_dict = {'1':0,'2':0,'3':0,'4':0}
for i in Inp1:
	Inp_dict[i] +=1

ans = list()
for k in Inp_dict.keys():
	if Inp_dict[k] == 2 : ans.extend(k)

if len(ans) == 2: print('YES')
else: print('NO')

Submission status: Accepted

Solution code:
import collections

l=[]
for i in range(3):
  A1,A2=map(int,input().split())
  l.append(A1)
  l.append(A2)

c=collections.Counter(l).most_common()

if len(set(l))==4 and c[0][1]==2:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

li_w = [a1, b1, a2, b2, a3, b3]

result = [li_w.count(i) for i in range(1, 5)]
if result.count(2) == 2 and result.count(1) == 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

if max(x) <= 2:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
deg = [0] * 5
for _ in range(3):
  a,b = map(int,input().split())
  deg[a] += 1
  deg[b] += 1

bl = max(deg) <= 2
answer = 'YES' if bl else 'NO'
print(answer)

Submission status: Accepted

Solution code:
ab=[list(map(int,input().split())) for i in range(3)]
cnt=[0,0,0,0]
ans='YES'
for i in ab:
    for j in i:
        cnt[j-1]+=1
for i in cnt:
    if i>=3:
        ans='NO'
print(ans)

Submission status: Accepted

Solution code:
ab=[]
for _ in range(3):
    a,b = map(int,input().split())
    ab.append(a)
    ab.append(b)
for i in range(1,5):
    if ab.count(i)>=3:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = list(cnt.values())
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

ans = "YES"

for i in range(4):
  a = lis.count(i+1)
  if a >= 3:
    ans = "NO"
    break
print(ans)

Submission status: Accepted

Solution code:
city={1:0,2:0,3:0,4:0}
for q in range(3):
    n,k=map(int,input().split())
    city[n]+=1
    city[k]+=1


if min(city.values()) ==0 or max(city.values())==3:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

a = list(mi()) + list(mi()) + list(mi())
cnts = [a.count(i) for i in range(1,5)]

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

Submission status: Accepted

Solution code:
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))

l = l1 + l2 + l3

cnt = []
for i in range(1,5):
    c = 0
    for j in l:
        if i == j:
            c += 1
    cnt.append(c)

cnt.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Path
https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_b

"""
import sys


def solve(path):
    res = [0] * 5
    for a, b in path:
        res[a] += 1
        res[b] += 1
    res.sort()
    if res == [0, 1, 1, 2, 2]:
        return 'YES'
    return 'NO'


def main(args):
    path = [[int(i) for i in input().split()] for _ in range(3)]
    ans = solve(path)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li = []
for i in range(3):	
  a,b = map(int,input().split())
  li.append(a)
  li.append(b)
li.sort()
if li==[1, 2, 2, 3, 3, 4]:
  print("YES")
else:
  print("NO")