forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1144F-GraphWithoutLongDirectedPaths.cpp
45 lines (37 loc) · 1.08 KB
/
1144F-GraphWithoutLongDirectedPaths.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdio>
#include <vector>
void dfs(long node, long from, const std::vector<std::vector<long> > &g, std::vector<long> &v){
if(v[node]){return;}
v[node] = 3 - v[from];
for(long p = 0; p < g[node].size(); p++){
long next = g[node][p];
if(v[next]){continue;}
dfs(next, node, g, v);
}
return;
}
int main(){
long n, m; scanf("%ld %ld", &n, &m);
std::vector<std::vector<long> > g(n + 1);
std::vector<long> v(n + 1, 0), t(m, 0);
std::vector<std::pair<long, long> > h(m);
for(long p = 0; p < m; p++){
long x, y; scanf("%ld %ld", &x, &y);
g[x].push_back(y); g[y].push_back(x);
h[p] = std::make_pair(x, y);
}
v[0] = 2;
dfs(1, 0, g, v);
bool possible(true);
for(long p = 0; p < m; p++){
long x(h[p].first), y(h[p].second);
if(v[x] == v[y]){possible = false; break;}
else if(v[x] == 2 && v[y] == 1){t[p] = 1;}
}
if(possible){
puts("YES");
for(long p = 0; p < m; p++){printf("%ld", t[p]);}
}
else{puts("NO");}
return 0;
}