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];
- vector<bool> visited;
- int dfs(int node)
- {
- int visnr = 1;
- visited[node] = true;
- for (int i = 0; i < (int)graph[node].size(); i++)
- if (!visited[graph[node][i]])
- visnr += dfs(graph[node][i]);
- return visnr;
- }
- int main()
- {
- cin >> peeks >> links;
- int node;
- visited.resize(peeks + 1);
- 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 = dfs(node);
- cout << endl << visnr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement