The program returns me 1. I think that there is a mistake in one of the cycles. But I cant find where.
Code:#include<iostream> #include<vector> #include<queue.h> #define NMAX 1024 using namespace std; vector <int> a[NMAX]; int n; int s[NMAX]; void input() { int m; cin>>n>>m; for(int i=1;i<=m;i++) { int u,v; cin>>u>>v; a[u].push_back(v); a[v].push_back(u); } } int used[100]; void bfs(int u) { queue<int>q; q.push(u); while(!q.empty()) { u=q.front(); q.pop(); cout<<u<<" "; for(int j=0;j<a[u].size();j++) { int v=a[u][j]; if(s[v]==0); s[v]=1; } } cout<<endl; } int main() { input(); bfs(1); return 0; }



LinkBack URL
About LinkBacks



