You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const int M = N << 1;
int adj[N], nxt[M], to[M], col[N], ecnt;
bool vis[N];
inline void addEdge(int f, int t)
{
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
ecnt++;
}
int main()
{
memset(adj, -1, sizeof(adj));
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0, u, v; i < m; i++)
{
cin >> u >> v;
addEdge(u, v);
addEdge(v, u);
}
queue<pair<int, int>> Q;
for (Q.push(make_pair(1, 0)), vis[1] = true; !Q.empty(); Q.pop())
{
auto [x, c] = Q.front();
for (int e = adj[x]; ~e; e = nxt[e])
if (!vis[to[e]])
{
col[to[e]] = c ^ 1;
vis[to[e]] = true;
Q.push(make_pair(to[e], c ^ 1));
}
}
bool flag = true;
for (int i = 1; i <= n; i++)
for (int e = adj[i]; ~e; e = nxt[e])
if (col[to[e]] == col[i])
flag = false;
if (flag)
{
puts("YES");
for (int i = 0; i < m; i++)
putchar('0' + col[to[i << 1]]);
putchar('\n');
}
else
puts("NO");
return 0;
}