-
Notifications
You must be signed in to change notification settings - Fork 214
/
graph.cpp
123 lines (102 loc) · 2.37 KB
/
graph.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
using namespace chrono;
#define endl "\n"
#define _USE_MATH_DEFINES
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define int long long int
#define pb push_back
#define mk make_pair
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define ub upper_bound
#define lb lower_bound
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define fr first
#define sc second
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
int const N=3*1e5+10;
//int const INF=1e18;
int mod=1e9+7;
int mod1=998244353;
const int INF=1e4;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int n,m;
vector<int>g[N];
vector<bool>vis;
vector<int>col;
bool dfs(int v){
vis[v]=1;
// cout<<v<<" ";
for(auto &ch: g[v]){
if(col[ch]==col[v])return false;
if(vis[ch])continue;
//cout<<ch<<" ";
col[ch]=1-col[v];
if(!dfs(ch))return false;
}
return true;
}
void solve(){
cin>>n>>m;
vis.resize(n+1,0);
col.resize(n+1,-1);
vector<vector<int>>edge;
rep(i,0,m){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
edge.pb({u,v});
}
col[1]=0;
if(!dfs(1)){
cout<<"NO"<<endl;
return;
}
cout<<"YES"<<endl;
//string ans="";
// rep(i,1,n)cout<<col[i]<<" ";
//cout<<endl;
for(auto &x: edge){
if(col[x[0]]==0 && col[x[1]]==1)cout<<"0";
else cout<<"1";
}
//cout<<ans<<endl;
//rep(i,1,n)cout<<col[i]
return;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("INPUT1.txt","r",stdin);
freopen("out1.txt","w",stdout);
#endif
fastio();
auto start1 = high_resolution_clock::now();
int t=1;
// cin>>t;
// precompute();
//fill_dp();
while(t--){
solve();
}
auto stop1 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
cout << "Time: " << duration . count() / 1000 <<"ms"<<endl;
#endif
return 0;
}