From 1f9da87c129e3763f94af46f8038b7123ee88840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Hl=C3=A1sek?= Date: Mon, 3 Aug 2020 23:57:57 -0700 Subject: [PATCH] Fix global variable name for connected_component_with_dsu. --- graph/connected_components_with_dsu.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index 71731e9da..50d0c4242 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -2,13 +2,13 @@ #include #include -int N; // denotes number of nodes; +int number_of_nodes; // denotes number of nodes; std::vector parent; -std::vector siz; +std::vector connected_set_size; void make_set() { // function the initialize every node as it's own parent - for (int i = 1; i <= N; i++) { + for (int i = 1; i <= number_of_nodes; i++) { parent[i] = i; - siz[i] = 1; + connected_set_size[i] = 1; } } // To find the component where following node belongs to @@ -23,26 +23,26 @@ void union_sets(int a, int b) { // To join 2 components to belong to one a = find_set(a); b = find_set(b); if (a != b) { - if (siz[a] < siz[b]) { + if (connected_set_size[a] < connected_set_size[b]) { std::swap(a, b); } parent[b] = a; - siz[a] += siz[b]; + connected_set_size[a] += connected_set_size[b]; } } int no_of_connected_components() { // To find total no of connected components std::set temp; // temp set to count number of connected components - for (int i = 1; i <= N; i++) temp.insert(find_set(i)); + for (int i = 1; i <= number_of_nodes; i++) temp.insert(find_set(i)); return temp.size(); } // All critical/corner cases have been taken care of. // Input your required values: (not hardcoded) int main() { - std::cin >> N; - parent.resize(N + 1); - siz.resize(N + 1); + std::cin >> number_of_nodes; + parent.resize(number_of_nodes + 1); + connected_set_size.resize(number_of_nodes + 1); make_set(); int edges = 0; std::cin >> edges; // no of edges in the graph