标签:acm
#include <bits/stdc++.h> using namespace std; #define maxn 1000000 + 10 int n, m; int color[maxn]; vector<int> G[maxn]; bool dfs(int u, int c) { color[u] = c; for(int i=0; i<G[u].size(); i++) { int &t = G[u][i]; if(color[t] == c) return false; if(!color[t] && !dfs(t, -c)) return false; } return true; } void solve() { for(int i=0; i<n; i++) if(!color[i]) { if(!dfs(i, 1)) { cout<<"NO"<<endl; return ; } } cout<<"YES"<<endl; } int main() { while(~scanf("%d%d", &n, &m)) { memset(color, 0, sizeof(color)); for(int i=0; i<n; i++) G[i].clear(); for(int i=0; i<m; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } solve(); } return 0; }
标签:acm
原文地址:http://blog.csdn.net/dojintian/article/details/44957571