Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- vector<int>*mat;
- unsigned int n,m;
- void Citire()
- {
- f>>n>>m;
- for(int i=1;i<=m;i++)
- {
- int x,y;
- f>>x>>y;
- mat[x].push_back(y);
- }
- }
- void Bfs(int k)
- {
- bool *seen = new bool[n];
- for(int i=0;i<=n;i++)
- seen=false;
- queue<int>coada;
- vector<int>::iterator index;
- coada.push(k);seen[k]=true;
- while(!coada.empty())
- {
- int nod_curent=coada.front();
- cout<<nod_curent<<" ";
- coada.pop();
- for(index=mat[nod_curent].begin();index!=mat[nod_curent].begin();index++)
- if(!seen[*index])
- {
- seen[*index]=true;
- coada.push(*index);
- }
- }
- }
- int main()
- {
- Citire();
- Bfs(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement