Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <fstream>
- using namespace std;
- ifstream input("pathbge1.in", ios_base::in);
- ofstream output("pathbge1.out", ios_base::out);
- const int MARKED = INT32_MAX;
- int main(){
- int n,m,b,e;
- input >> n >> m;
- vector<int> graph[n];
- for (int i = 0; i < m; i++) {
- input >> b >> e;
- --b;
- --e;
- graph[e].push_back(b);
- graph[b].push_back(e);
- }
- queue<int> queue;
- queue.push(0);
- vector<int> cur(n, MARKED);
- cur[0] = 0;
- while (!queue.empty()){
- int v = queue.front();
- queue.pop();
- for (auto path : graph[v]) {
- if(cur[path] == MARKED) {
- cur[path] = cur[v] + 1;
- queue.push(path);
- }
- }
- }
- for (auto path : cur) {
- output << path << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement