You are given a connected undirected graph consisting of $n$ vertices and $m$ edges. There are no self-loops or multiple edges in the given graph.

You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).


-----Input-----

The first line contains two integer numbers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le 2 \cdot 10^5$) — the number of vertices and edges, respectively.

The following $m$ lines contain edges: edge $i$ is given as a pair of vertices $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). There are no multiple edges in the given graph, i. e. for each pair ($u_i, v_i$) there are no other pairs ($u_i, v_i$) and ($v_i, u_i$) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).


-----Output-----

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.

Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length $m$. The $i$-th element of this string should be '0' if the $i$-th edge of the graph should be directed from $u_i$ to $v_i$, and '1' otherwise. Edges are numbered in the order they are given in the input.


-----Example-----
Input
6 5
1 5
2 1
1 4
3 1
6 1

Output
YES
10100



-----Note-----

The picture corresponding to the first example: [Image]

And one of possible answers: $\text{of}$

Difficulty: introductory

Starter code:

Solutions:
n, m = map(int, input().split())
clr = [-1 for i in range(0, n)]
eds = []


def dfs():
    cur = 0
    st = [-1 for i in range(0, n + 1)]
    st[cur] = 0
    cur += 1
    while cur > 0:
        v = st[cur - 1]
        cur -= 1
        for x in g[v]:
            if clr[x] != -1:
                if clr[x] == clr[v]:
                    return False
                continue
            clr[x] = clr[v] ^ 1
            st[cur] = x
            cur += 1
    return True


g = [[] for i in range(0, n)]
for i in range(0, m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
    eds.append((u, v))
clr[0] = 0
if dfs():
    print("YES")
    print("".join("1" if clr[u] < clr[v] else "0" for (u, v) in eds))
else:
    print("NO")

import sys
from collections import deque
input = sys.stdin.readline

n,m=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(m)]

EDGELIST=[[] for i in range(n+1)]

for x,y in EDGE:
    EDGELIST[x].append(y)
    EDGELIST[y].append(x)

QUE=deque([[1,1]])
ANS=[-1]*(n+1)
ANS[1]=1


while QUE:
    x,color=QUE.pop()
    ANS[x]=color

    for to in EDGELIST[x]:
        if ANS[to]==color:
            print("NO")
            return

        if ANS[to]==-1:
            QUE.appendleft([to,abs(color-1)])

    
print("YES")
for x,y in EDGE:
    if ANS[x]==1:
        print("1",end="")
    else:
        print("0",end="")
        


import sys


def input():
    return sys.stdin.readline()


n, m = map(int, input().split())
give = [False] * (n + 1)
take = [False] * (n + 1)
edge = dict()
inputs = []
for i in range(n):
    edge[i+1] = []
for i in range(m):
    u, v = map(int, input().split())
    inputs.append((u, v))
    edge[u].append(v)
    edge[v].append(u)
check = [False] * (n + 1)
queue = [1]
front = 0
while front < len(queue):
    u = queue[front]
    check[u] = True
    for v in edge[u]:
        if check[v]:
            continue
        queue.append(v)
        if (give[u] and give[v]) or (take[u] and take[v]):
            print('NO')
            return
        if (give[u] and take[v]) or (take[u] and give[v]):
            continue
        if give[u]:
            take[v] = True
            continue
        if take[u]:
            give[v] = True
            continue
        if give[v]:
            take[u] = True
            continue
        if take[v]:
            give[u] = True
            continue
        give[u] = True
        take[v] = True
    front += 1
print('YES')
for u, v in inputs:
    if give[u] and take[v]:
        print(1, end="")
    else:
        print(0, end="")
print()


#5671891
from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD=pow(10,9)+7

def IN(f=0):
    if f==0:
        return ( [int(i) for i in sys.stdin.readline().split()] )
    else:
        return ( int(sys.stdin.readline()) )

    
def bfs(s):
    i=1
    parent[s]=-1
    vis[s]=1
    frontier=[s]
    while frontier:
        nex=[]
        for u in frontier:
            for v in d[u]:
                if vis[v]==0:
                    vis[v]=1
                    color[v]=color[u]^1
                    parent[v]=u
                    nex.append(v)
        frontier=nex
        i+=1
    return(parent)

n,m=IN()
d=DD(list)
d1=[]
for i in range(m):
    u,v=IN()
    d[u].append(v)
    d[v].append(u)
    d1.append([u,v])

vis=[0 for i in range(n+1)]

color=[0 for i in range(n+1)]

parent=dict()
for i in range(1,n+1):
    if vis[i]==0:
        bfs(i)
#print(color)

flag=0
for i in d:
    for j in d[i]:
        if color[j]!=color[i]^1:
            flag=1
            break
    if flag==1:
        break


#print("fjfj")
if flag==1:
    print("NO")
else:
    ans=""
    for i,j in d1:
        if color[i]==0 and color[j]==1:
            ans+=str(1)
        else:
            ans+=str(0)
        
    print("YES")
    print(ans)
    


#5671891
from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD=pow(10,9)+7

def IN(f=0):
    if f==0:
        return ( [int(i) for i in sys.stdin.readline().split()] )
    else:
        return ( int(sys.stdin.readline()) )

    
def bfs(s):
    i=1
    parent[s]=-1
    vis[s]=1
    frontier=[s]
    while frontier:
        nex=[]
        for u in frontier:
            for v in d[u]:
                if vis[v]==0:
                    vis[v]=1
                    color[v]=color[u]^1
                    parent[v]=u
                    nex.append(v)
        frontier=nex
        i+=1
    return(parent)

n,m=IN()
d=DD(list)
d1=[]
for i in range(m):
    u,v=IN()
    d[u].append(v)
    d[v].append(u)
    d1.append([u,v])

vis=[0 for i in range(n+1)]

color=[0 for i in range(n+1)]

parent=dict()
bfs(1)
#print(color)

flag=0
for i in d:
    for j in d[i]:
        if color[j]!=color[i]^1:
            flag=1
            break
    if flag==1:
        break


#print("fjfj")
if flag==1:
    print("NO")
else:
    ans=""
    for i,j in d1:
        if color[i]==0 and color[j]==1:
            ans+=str(1)
        else:
            ans+=str(0)
        
    print("YES")
    print(ans)
    


graph = [[] for _ in range(200000)]
colors = [0] * 200000
vis = [0] * 200000

def main():
    n, m = map(int, input().split())
    edges = []
    for i in range(m):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        graph[u].append(v)
        graph[v].append(u)
        edges.append((u, v))
    
    colors[0] = 1
    queue = [(0, 1)]
    i = 0
    while i != len(queue):
        for v in graph[queue[i][0]]:
            if not colors[v]:
                colors[v] = 3 - queue[i][1]
                queue.append((v, colors[v]))
        i += 1
    
    ans = ['0'] * m
    for i in range(m):
        if colors[edges[i][0]] == colors[edges[i][1]]:
            print("NO")
            return 0
        if colors[edges[i][0]] == 1:
            ans[i] = '1'
    print("YES")
    print("".join(ans))
    return 0
main()

#!/usr/bin/env python
from collections import deque

n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
e = []
for _ in range(m):
	u, v = [int(_) - 1 for _ in input().split()]
	e.append((u, v))
	g[u].append(v); g[v].append(u)

p = [-1 for _ in range(n)]
p[0] = True
ok = True
q = deque([0])
while q:
	f = q.popleft()
	for t in g[f]:
		if p[t] == -1:
			q.append(t)
			p[t] = not p[f]
		elif p[t] == p[f]:
			ok = False

if not ok:
	print('NO')
else:
	print('YES')
	print(''.join(('1' if p[e[i][0]] else '0') for i in range(m)))