Problem:


Score : 500 points

Problem Statement

Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.

First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.

Then, Aoki gave him M queries. The i-th of them is as follows:

Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.

After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number.
However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.

Determine whether there exists a tree that has the property mentioned by Takahashi.

Constraints

2 ≤ N ≤ 10^5

1 ≤ M ≤ 10^5

1 ≤ a_i,b_i ≤ N

a_i ≠ b_i

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
:
a_M b_M

Output

Print YES if there exists a tree that has the property mentioned by Takahashi; print NO otherwise.

Sample Input 1

4 4
1 2
2 4
1 3
3 4

Sample Output 1

YES

For example, Takahashi's graph has the property mentioned by him if it has the following edges: 1-2, 1-3 and 1-4.
In this case, the number written at every edge will become 2.

Sample Input 2

5 5
1 2
3 5
5 1
3 4
2 3

Sample Output 2

NO



Sample input:
4 4
1 2
2 4
1 3
3 4


Sample output:
YES

Submission status: Accepted

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

l=[0 for _ in range(n)]

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

c=0
for i in range(n):
  if l[i]%2==1:
    c+=1
    break

if c==0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[0]*n
for _ in range(m):
  l,r=map(int,input().split())
  a[l-1]+=1
  a[r-1]-=1
for i in range(n-1):
  a[i+1]+=a[i]
print(['YES','NO'][any([i%2 for i in a])])

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    N, M = MAP()
    d = defaultdict(int)
    for i in range(M):
        a, b = MAP()
        d[a] += 1
        d[b] += 1

    ans = "YES"
    for x in d.values():
        if x % 2 == 1:
            ans = "NO"
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline().strip()
from collections import Counter

def main():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    ca = Counter(A)
    cb = Counter(B)
    c = ca + cb
    
    if all(count%2 == 0 for count in c.values()):
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#coding: utf-8
from collections import defaultdict
import sys

N, M = (int(x) for x in input().split())
freq = defaultdict(int)

for i in range(M):
    a, b = (int(x) for x in input().split())
    freq[a] += 1
    freq[b] += 1

for k in freq:
    if freq[k] % 2 == 1:
        print ("NO")
        sys.exit(0)

print ("YES")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

from collections import deque
def main():
    n, m = mi()
    cc = [0]*n
    for _ in range(m):
        a, b = mi()
        a -= 1
        b -= 1 
        cc[a] += 1
        cc[b] += 1
    for x in cc:
        if x%2 == 1:
            print('NO')
            return
    print('YES')



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def agc014_b():
    n, m = map(int, input().split())
    deg = [0]*n
    for _ in range(m):
        a, b = map(lambda x: int(x)-1, input().split())
        deg[a] += 1
        deg[b] += 1
    for k in deg:
        if k%2 == 1:
            return print('NO')
    print('YES')

if __name__ == '__main__':
    agc014_b()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
counter=[0 for i in range(n)]
for i in range(m):
    a,b=MI()
    counter[a-1]+=1
    counter[b-1]+=1
for i in range(n):
    if counter[i]%2==1:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    counter = defaultdict(int)
    for _ in range(M):
        A, B = map(lambda x: int(x) - 1, input().split())
        counter[A] += 1
        counter[B] += 1
    is_valid = True
    for v in counter.values():
        if v % 2 == 1:
            is_valid = False
            break
    if is_valid:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    cnt = [0] * N
    for _ in range(M):
        a, b = LI_()
        cnt[a] += 1
        cnt[b] += 1

    # 「全ての頂点が偶数回登場する」は必要条件
    # 奇数回登場する頂点があると、それに繋がる辺の中に必ず奇数になる辺が出るから
    # 深さ1の木を考えると、全ての頂点が偶数回登場するならば、
    # 葉iの登場回数=葉iに繋がる辺の数字より、全ての辺の数字が偶数
    if len([i for i in cnt if i % 2 == 0]) == N:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
for i in range(M):
	a[i], b[i] = map(int, input().split())
	a[i] -= 1
	b[i] -= 1

cnt = [0 for i in range(N)]
for i in range(M):
	cnt[a[i]] += 1
	cnt[b[i]] += 1
for i in cnt:
	if i % 2 == 1:
		print("NO")
		break
else:
	print("YES")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = [0 for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    p[a - 1] += 1
    p[b - 1] += 1
flag = True
for i in range(n):
    if p[i] % 2 == 1:
        flag = False
        break
if flag == True:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

edge=[0]*(n+1)

for _ in range(m):
    a,b=map(int,input().split())
    a,b=min(a,b),max(a,b)
    edge[a]+=1
    edge[b]-=1

for i in range(1,n+1):
    edge[i]+=edge[i-1]

for i in range(1,n):
    if edge[i]%2==1:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy
def fprint(c):
    print(c)
    sys.stdout.flush()
def solve():
    n, m = getList()
    g = [[] for i in range(n+1)]
    ji = [0 for i in range(n+1)]


    for i in range(m):
        a, b = getList()
        g[a].append(b)
        g[b].append(a)
        ji[a] += 1
        ji[b] += 1
    # print(ji)
    # print(g)
    ni = 0
    for i in range(1, n+1):
        if ji[i] % 2 == 1:
            for q in g[i]:
                if ji[q] % 2 == 0:
                    print("NO")
                    return
        else:
            ni += 1
    if ni < 2:
        print("NO")
        return
    print("YES")

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [0] * (n + 1)
for _ in range(m):
    x, y = map(int, input().split())
    a[x] = (a[x] + 1) & 1
    a[y] = (a[y] + 1) & 1
print("YES" if sum(a) == 0 else "NO")

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = np.zeros(n + 1, dtype=int)
for _ in range(m):
    x, y = map(int, input().split())
    a[x] = (a[x] + 1) & 1
    a[y] = (a[y] + 1) & 1
print("YES" if np.sum(a) == 0 else "NO")

Submission status: Accepted

Solution code:
from collections import defaultdict
# d = defaultdict(int)で0で初期化
# d = defaultdict(lambda: 100)で100で初期化
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, m = map(int, input().split())
es = [defaultdict(int) for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    es[a][b] += 1
    es[b][a] += 1
    if es[a][b] == 2:
        es[a].pop(b)
        es[b].pop(a)

def dfs(v, p, r):
    for i in es[v]:
        if i != p:
            es[i].pop(v)
            es[v].pop(i)
            if i == r:
                return - 1
            else:
                return dfs(i, v, r)
    return - 2

for i in range(n):
    if es[i]:
        if dfs(i, -1, i) == -2:
            print("NO")
            exit()
print("YES")

Submission status: Accepted

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

ans = "YES"
for i in range(n):
    if cnt[i] % 2 == 1:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    ans[a]+=1
    ans[b]+=1
for i in range(n):
    if ans[i]%2==1:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
#n<=10**5

tree=[0]*n

for _ in range(m):
    x,y=map(int,input().split())
    tree[x-1]+=1
    tree[y-1]+=1

for item in tree:
    if item%2==1:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
def solve(n, m, a, b):
    D = {(i+1): 0 for i in range(n)}
    for v in a + b:
        D[v] += 1
    ok = len(list(
        filter(lambda num: num % 2 == 0, D.values())
    )) == n
    return "YES" if ok else "NO"

n, m = map(int, input().split())
ab = [map(int, input().split()) for i in range(m)]
a, b = zip(*ab)
print(solve(n, m, a, b))

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
count = defaultdict(int)
for _ in range(M):
    a, b = map(int, input().split())
    count[a] += 1
    count[b] += 1
flag = True
for k, v in count.items():
    if v % 2 == 1:
        flag = False
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N,M=list(map(int,input().split()))
road = [0]*(N)
for _ in range(M):
    l,r=map(int,input().split())
    road[l-1]+=1
    road[r-1]-=1
road = list(itertools.accumulate(road))[:-1]

flag=0
for ro in road:
    if ro%2==1:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
c = defaultdict(int)
for _ in range(M):
    a, b = map(int, input().split())
    c[a] += 1
    c[b] += 1

flag = True
for k, v in c.items():
    if v % 2 != 0:
        flag = False
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import Counter
n,m,*ab = map(int,open(0).read().split())
a = Counter(ab)
for i in a.values():
  if i%2 != 0:
    print("NO")
    break
else:
  print("YES")

Submission status: Accepted

Solution code:
# code like professional "write main function"
def main():
	# we can always make a tree from the given set of nodes what we like
	# any possible tree
	n , m = map(int , input().split())
	deg = [0 for i in range(n+2)]
	for i in range(m):
		x , y = map(int , input().split())
		deg[x]+=1
		deg[y]+=1
	f=0
	# traversing a node would add 1 to one of its outgoing edges
	# if the out going edges need to have 0 parity than it should occur even no ot times
	for i in range(1, n+1):
		if deg[i]%2==1:
			f = 1
	if f:
		print("NO")
	else:
		print("YES")
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:

def main():
	n , m = map(int , input().split())
	deg = [0 for i in range(n+2)]
	for i in range(m):
		x , y = map(int , input().split())
		deg[x]+=1
		deg[y]+=1
	f=0
	for i in range(1, n+1):
		if deg[i]%2==1:
			f = 1
	if f:
		print("NO")
	else:
		print("YES")
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    odds = set()
    for _ in range(M):
        for c in read_ints():
            if c in odds:
                odds.discard(c)
            else:
                odds.add(c)
    if odds:
        return 'NO'
    return 'YES'


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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
nm = [list(map(int,input().split())) for _ in range(m)]

cnt = [0] * n

for n,m in nm:
    cnt[n-1] += 1
    cnt[m-1] += 1

if all([i % 2 == 0 for i in cnt]):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
N,M = map(int, input().split())

A = [0 for _ in range(N)]
for _ in range(M):
  a,b = map(int, input().split())
  a,b = a-1, b-1
  A[a] += 1
  A[b] += 1
  
for a in A:
  if a%2 == 1:
    print("NO")
    exit(0)
print("YES")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc014/tasks/agc014_b

n, m = map(int, input().split())
edges = [0] * n
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a, b))

for a, b in ab:
    edges[a - 1] += 1
    edges[b - 1] += 1

for e in edges:
    if e % 2 == 1:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
ab = (list(map(int, input().split())) for _ in range(m))

cnt = defaultdict(int)
for a, b in ab:
    cnt[a] += 1
    cnt[b] += 1
ans = all(cnt[i] % 2 == 0 for i in cnt)
print('YES' if ans else 'NO')

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate

    n, m = map(int, readline().split())
    c = [0] * n

    for i in range(m):
        a, b = map(int, readline().split())
        a, b = a - 1, b - 1
        a, b = min(a, b), max(a, b)
        c[a] += 1
        c[b] -= 1

    d = list(accumulate(c))

    if all((x % 2 == 0 for x in d)):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N, M = MAP()

a, b = ZIP(M)

a_cnt, b_cnt = Counter(a), Counter(b)

for i in range(1, N+1):
	if (a_cnt[i]+b_cnt[i])%2 != 0:
		print("NO")
		break
else:
	print("YES")

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, gcd, 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 heapq import heappush, heappop
from functools import reduce
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 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M = MAP()

node = []
for _ in range(M):
	a, b = MAP()
	node.append(a-1)
	node.append(b-1)

for x in Counter(node).values():
	if x%2:
		print("NO")
		break
else:
	print("YES")

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n, m = map(int, sys.stdin.readline().split())
cAB = Counter()
for i in range(m):
    a,b = map(int, sys.stdin.readline().split())
    cAB[a] += 1
    cAB[b] += 1
print('YES' if all([cAB[key]%2==0 for key in cAB.keys()]) else 'NO')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = [0 for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    cnt[a] = (cnt[a] + 1) % 2
    cnt[b] = (cnt[b] + 1) % 2
if 1 in cnt:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

dis = [0] * n

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

for i in range(n):
    if dis[i] % 2 == 1:
        print("NO")
        exit(0)

print("YES")

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
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)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m = lr()
x = [0 for i in range(n-1)]
for i in range(m):
    a,b = lr()
    a,b = min(a,b), max(a,b)
    a-=1
    b-=1
    x[a]+=1
    if b != n-1:
        x[b]-=1
x1 = [0]
for i in range(n-1):
    x1.append(x1[-1]+x[i])
flag = True
for num in x1:
    if num%2 == 1:
        flag = False
        break
if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lis = [0] * N
for i in range(M):
    a,b = map(int,input().split())
    lis[a-1] += 1
    lis[b-1] += 1
ans = 'YES'
for i in lis:
    if i % 2 == 1:
        ans = 'NO'
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N, M = map(int, input().split())
tree = []
for _ in range(M):
    a, b = map(int, input().split())
    tree.append(a)
    tree.append(b)

dic = Counter(tree)

f = 1
for v in dic.values():
    if v%2:
        f = 0
        break

if f:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
cnt = [0]*n
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    cnt[a]+=1
    cnt[b]+=1
for i in range(n):
    if cnt[i]&1:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

tree = [0]*(N-1)

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        tree[b-2] += 1
    elif b == 1:
        tree[a-2] += 1
    else:
        tree[a-2] += 1
        tree[b-2] += 1

if all(tree[i] % 2 == 0 for i in range(N-1)):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, M = map(int, input().split())
    ans = [0] * N
    for _ in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        ans[a] = 1-ans[a]
        ans[b] = 1-ans[b]
    if 1 in ans:
        print('NO')
    else:
        print('YES')

if __name__ == "__main__":
    main()

Submission status: Accepted

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

N, M = map(int, input().split())
cnt = [0]*N

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

for i in range(N):
    if cnt[i]%2==1:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N, M = map(int, input().split())
    d = defaultdict(int)
    for _ in range(M):
        a, b = map(int, input().split())
        d[a] += 1
        d[b] += 1

    for i, j in d.items():
        if j % 2 == 1:
            print('NO')
            exit()

    print('YES')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, M = map(int, input().split())
A = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    A[a] += 1
    A[b] += 1

for a in A:
    if a % 2 == 1:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
v={}
for _ in range(m):
    a,b=map(int,input().split())
    v[a]=v.get(a, 0)+1
    v[b]=v.get(b, 0)+1

for ki,vi in v.items():
    if(vi%2!=0):
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
from itertools import accumulate

N, M = map(int, input().split())
acc = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    acc[a - 1] += 1
    acc[b - 1] -= 1
print("NO") if any(a % 2 for a in accumulate(acc)) else print("YES")

Submission status: Accepted

Solution code:
from itertools import accumulate

N, M = map(int, input().split())
acc = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    acc[a - 1] += 1
    acc[b - 1] -= 1
acc = list(accumulate(acc))
print("NO") if any(a % 2 for a in acc) else print("YES")

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, M = in_nn()
    d = defaultdict(int)
    for x in in_na():
        d[x] += 1

    ans = 'YES'
    for i in range(1, N + 1):
        if d[i] % 2 == 1:
            ans = 'NO'
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(int)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u] += 1
    ns[v] += 1
if all(val%2==0 for val in ns.values()):
    ans = "YES"
else:
    ans = "NO"
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = "YES"
cnt = [0]*n
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cnt[a] += 1
    cnt[b] += 1
for i in range(n):
    if cnt[i]%2 != 0:
        ans = "NO"
        break
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
dic = {}
for i in range(1,n+1):
  dic[i]=0
for i in range(m):
  a,b = map(int,input().split())
  dic[a] += 1
  dic[b] += 1
ret = 'YES'
for i in range(1,n+1):
  if dic[i]%2==1:
    ret = 'NO'
    break
print(ret)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = [0] * (n + 1)
for _ in range(m):
    a, b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1
for i in cnt:
    if not i % 2 == 0:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
n, m = [int(w) for w in input().split()]

node = [0] * (n+1)

for i in range(m):
    a, b = [int(w) for w in input().split()]
    node[a] ^= 1
    node[b] ^= 1

cond = all([w == 0 for w in node])
print("YES" if cond else "NO")