-
Notifications
You must be signed in to change notification settings - Fork 5
/
1144F.cpp
103 lines (96 loc) · 1.72 KB
/
1144F.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//21171_somesh || asomesh999
//AC
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;
vector<pii> edg;
vector<vi> edges, edges1;
vi visited;
map<pii, int> mp;
int flag = 0;
void dfs(int pos, int val) {
visited[pos] = 1;
val += 1;
for(auto it : edges[pos]) {
if(mp.find({pos, it}) == mp.end() && mp.find({it, pos}) == mp.end()) {
if(val % 2 == 0) {
edges1[it].push_back(pos);
mp[{it, pos}] = 1;
}
else {
edges1[pos].push_back(it);
mp[{pos, it}] = 1;
}
}
if(visited[it] == 0)
dfs(it, val);
}
}
void func(int pos) {
queue<int> q;
for(auto it : edges1[pos]) {
q.push(it);
}
while(!q.empty()) {
int u = q.front();
q.pop();
if(edges1[u].size()) {
flag = 1;
break;
}
}
}
int main()
{
io
#ifdef SOMU
clock_t startTime = clock();
freopen("input.txt","r",stdin);
#endif
int n, m;
cin >> n >> m;
edges.resize(n);
edges1.resize(n);
visited.resize(n);
edg.resize(m);
fr(i, 0, m) {
int u, v;
cin >> u >> v;
u--, v--;
edg[i] = {u, v};
edges[u].push_back(v);
edges[v].push_back(u);
}
dfs(0, 0);
string s;
flag = 0;
fr(i, 0, n) {
if(flag) break;
func(i);
}
if(flag) cout << "NO";
else {
fr(i, 0, m) {
pii a = edg[i];
if(mp.find(a) != mp.end()) {
s.push_back('0');
} else {
s.push_back('1');
}
}
cout << "YES\n";
cout << s;
}
#ifdef SOMU
cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
#endif
return 0;
}