题目:没有网址
题意:
题解:
建立图搜索ok
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<algorithm> #include<map> #define maxn 10005 using namespace std; vector<int>G[maxn]; int v; int color[maxn]; bool dfs(int v,int c) { color[v]=c; //cout<<G[v].size(); for(int i=0;i<G[v].size();i++) { //cout<<color[G[v][i]]<<" "<<G[v][i]<<endl; if(color[G[v][i]]==c)return false; if(color[G[v][i]]==0&&!dfs(G[v][i],-c))return false; } return true; } void solve(int v){ //cout<<"a"<<endl; for(int i=0;i<v;i++) { if(color[i]==0){ // cout<<"a"<<endl; if(dfs(i,1)==true) { cout<<"yes"<<endl; return ; } } } cout<<"no"<<endl; } int main() { int v,e; cin>>v>>e; memset(color,0,sizeof(color)); for(int i=0;i<e;i++) { int s,t; cin>>s>>t; G[s].push_back(t); G[t].push_back(s); } // cout<<G[0].size(); solve(v); return 0; }
时间: 2024-10-31 09:12:29