F. Graph Without Long Directed Paths

You are given a connected undirected graph consisting of ? vertices and ?

edges. There are no self-loops or multiple edges in the given graph.

You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).

Input

The first line contains two integer numbers ?

and ? (2≤?≤2⋅105, ?−1≤?≤2⋅105

) — the number of vertices and edges, respectively.

The following ?

lines contain edges: edge ? is given as a pair of vertices ??, ?? (1≤??,??≤?, ??≠??). There are no multiple edges in the given graph, i. e. for each pair (??,??) there are no other pairs (??,??) and (??,??

) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).

Output

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.

Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length ?

. The ?-th element of this string should be '0' if the ?-th edge of the graph should be directed from ?? to ??

, and '1' otherwise. Edges are numbered in the order they are given in the input.

Example

Input

Copy

6 5
1 5
2 1
1 4
3 1
6 1

Output

Copy

YES
10100

Note

The picture corresponding to the first example:

And one of possible answers:

题解:题目要求建立有向边,使得路径最长为1,其实就是从一个点出发只能走一步了,我们可以将建边的工作转化为给点进行的操作,可以给这n个点进行01染色操作,使得任意两点有直达边且该两点染色不同。不妨设该点染色为0表示与这个点相连的边都是出边,1表示与这个点相连的边都是入边。由于01的地位是一样的,不管从那个点开始或者染什么颜色都是一样的结果,则我们可以找任意一个点进行DFS染色操作,若染色操作中遇到了连续两点染色相同的情况,则输出NO,否则对于每一条边输出该边起点被染的颜色就好了。

#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int color[maxn],a[maxn],b[maxn];
vector<int>G[maxn];
void DFS(int now,int pre,int col)
{
    color[now]=col;
    for(int i=0;i<G[now].size();i++){
        int to=G[now][i];
        if(to==pre)
            continue;
        else if(color[to]==-1)
            DFS(to,now,1-col);
        else if(color[now]==color[to]){
            puts("NO");
            exit(0);
        }
    }
}
int main()
{
    memset(color,-1,sizeof(color));
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    DFS(1,0,0);
    puts("YES");
    for(int i=1;i<=m;i++)
    {
        if(color[a[i]]==1)
            cout<<"1";
        else
            cout<<"0";
    }
    cout<<endl;
    return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值