#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=1e5+10;
int h[N],e[N*2],ne[N*2],idx;
int color[N];
void add(int a,int b){
    e[idx]=b;
    ne[idx]=h[a];
    h[a]=idx++;
}

bool dfs(int u,int c){
    color[u]=c;

    for(int i=h[u];i!=-1;i=ne[i]){
        int j=e[i];
        if(!color[j] && !dfs(j,-c)) return false;//没有被染,或者染色失败
        if(color[j]==c) return false;//染色冲突
    }
    return true;
}

int main(){
    memset(h,-1,sizeof h);
    cin>>n>>m;
    while(m--){
        int a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    bool flag=true;
    for(int i=1;i<=n;i++){
        if(!color[i]){
            if(!dfs(i,1)){
                flag=false;
                break;
            }
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

 posted on 2019-08-22 15:51  谁是凶手1703  阅读(57)  评论(0)    收藏  举报