Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define MAXPEEKSNR 100
- int peeks, links;
- vector<int> graph[MAXPEEKSNR];
- int bfs(int startNode)
- {
- queue<int> bfsQueue;
- vector<bool> visited(peeks + 1, false);
- unsigned visnr = 0;
- bfsQueue.push(startNode);
- visited[startNode] = true;
- while (!bfsQueue.empty())
- {
- int currNode = bfsQueue.front();
- bfsQueue.pop();
- for (int i = 0; i < (int)graph[currNode].size(); i++)
- {
- if (!visited[graph[currNode][i]])
- {
- visited[graph[currNode][i]] = true;
- bfsQueue.push(graph[currNode][i]);
- }
- }
- //cerr << currNode << ' ';
- visnr++;
- }
- return visnr;
- }
- int main()
- {
- cin >> peeks >> links;
- int node;
- for (int i = 0; i < links; i++)
- {
- int x, y;
- cin >> x >> y;
- graph[x].push_back(y);
- graph[y].push_back(x);
- node = x;
- }
- int visnr = bfs(node);
- cout << endl << visnr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement