Artifact Air cool! is a simple deep search and wide search!
#include <iostream>#include<queue>using namespacestd;BOOLmap[Ten][Ten];BOOLdfsed[Ten];intN, E;queue<int>Q;BOOLbfsed[Ten];voidBFsintx);voidDfsintx);intMain () {CIN>> N >>e; for(inti =0; I < E; i++){ intA, B; CIN>> a >>b; MAP[A][B]= Map[b][a] =true; } for(inti =0; I < n; i++){ if(Dfsed[i] = =false) {Dfsed[i]=true; cout<<"{ "; DFS (i); cout<<"}"; cout<<Endl; } } for(inti =0; I < n; i++){ if(Bfsed[i] = =false) {cout<<"{ "<< I <<" "; Q.push (i); Bfsed[i]=true; BFS (i); cout<<"}"<<Endl; } }}voidDfsintx) {cout<< x <<" "; for(inti =0; I < n; i++){ if(Dfsed[i] = =false&& map[x][i]==true) {Dfsed[i]=true; DFS (i); } }}voidBFsintx) { while(Q.empty ()! =true){ intK =Q.front (); Q.pop (); for(inti =0; I < n; i++){ if(Map[k][i] = =true&& Bfsed[i] = =false) {Bfsed[i]=true; cout<< I <<" "; Q.push (i); } } }}
List Components (25)