标签:turn back namespace const 算法 cout ack log dfs
挑战程序设计p97
#include<bits/stdc++.h> using namespace std; #define ll long long #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r const int INF=0x3f3f3f3f; const int N=1e5+5; vector<int>g[N]; int color[N]={0}; bool dfs(int u, int c) { color[u]=c; for(int i=0;i<g[u].size();i++) { if(color[g[u][i]]==c)return false; if(color[g[u][i]]==0&&!dfs(g[u][i],-c))return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++) { int t; cin>>t; while(t--) { int a; cin>>a; g[i].push_back(a); } } bool flag=dfs(0,1); if(flag)cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }
标签:turn back namespace const 算法 cout ack log dfs
原文地址:http://www.cnblogs.com/widsom/p/7250192.html