Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In the Name of Allah Most Gracious, Most Merciful//
- /*If you want something you've never had, you have to do something you never did.*/
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ll long long
- #define pii pair<int,int>
- #define pll pair<ll,ll>
- #define M 101007
- #define INF 1e9
- #define INFL 1e18
- #define PI acos(-1)
- #define mp make_pair
- //const int fx[]= {+1,-1,+0,+0};
- //const int fy[]= {+0,+0,+1,-1};
- //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
- //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
- //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
- //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
- int gcd(int a, int b)
- {
- return b ? gcd(b, a%b) : a;
- }
- int color[2*M+100];
- bool visited[2*M+100];
- vector<int>adj[2*M];
- bool dfs(int node)
- {
- for(int i=0;i<adj[node].size();i++)
- {
- int x=adj[node][i];
- if(visited[x]==false)
- {
- visited[x]=true;
- color[x]=!color[node];
- if(!dfs(x))
- return false;
- }
- else if(color[x]==color[node])
- return false;
- }
- return true;
- }
- int main()
- {
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // #endif
- int n,m;
- cin>>n>>m;
- vector<pii>v;
- for(int i=0;i<m;i++)
- {
- int x,y;
- cin>>x>>y;
- adj[x].pb(y);
- adj[y].pb(x);
- v.pb(mp(x,y));
- }
- memset(color,0,sizeof color);
- memset(visited,false,sizeof visited);
- visited[1]=true;
- bool ans=dfs(1);
- if(ans)
- {
- cout<<"YES"<<endl;
- for(int i=0;i<m;i++)
- {
- int x=v[i].first;
- int y=v[i].second;
- if(color[x]==0)
- {
- cout<<1;
- }
- else
- {
- cout<<0;
- }
- }
- cout<<endl;
- //cout<<endl;
- }
- else
- {
- cout<<"NO"<<endl;
- }
- //#ifdef LOCAL_DEFINE
- // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- // #endif
- ///Before submit=>
- /// *check for integer overflow,array bounds
- /// *check for n=1
- }
Advertisement
Add Comment
Please, Sign In to add comment