diff options
Diffstat (limited to '03-algorithms_on_graphs/01-decomposition/02-connected_components')
3 files changed, 28 insertions, 0 deletions
diff --git a/03-algorithms_on_graphs/01-decomposition/02-connected_components/connected_components.cpp b/03-algorithms_on_graphs/01-decomposition/02-connected_components/connected_components.cpp new file mode 100644 index 0000000..8e6b531 --- /dev/null +++ b/03-algorithms_on_graphs/01-decomposition/02-connected_components/connected_components.cpp @@ -0,0 +1,24 @@ +#include <iostream> +#include <vector> + +using std::vector; +using std::pair; + +int number_of_components(vector<vector<int> > &adj) { + int res = 0; + //write your code here + return res; +} + +int main() { + size_t n, m; + std::cin >> n >> m; + vector<vector<int> > adj(n, vector<int>()); + for (size_t i = 0; i < m; i++) { + int x, y; + std::cin >> x >> y; + adj[x - 1].push_back(y - 1); + adj[y - 1].push_back(x - 1); + } + std::cout << number_of_components(adj); +} diff --git a/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01 b/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01 new file mode 100644 index 0000000..174151f --- /dev/null +++ b/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01 @@ -0,0 +1,3 @@ +4 2 +1 2 +3 2 diff --git a/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01.a b/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01.a new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/03-algorithms_on_graphs/01-decomposition/02-connected_components/tests/01.a @@ -0,0 +1 @@ +2 |