fix: dynamically allocate all arrays

This commit is contained in:
coderanant
2020-05-22 01:06:40 +05:30
parent 19be84cf58
commit d3b60e0de8

View File

@@ -3,8 +3,8 @@
#include <set>
int N; // denotes number of nodes;
int parent[1000001];
int siz[1000001];
std::vector<int> parent;
std::vector<int> siz;
void make_set() { // function the initialize every node as it's own parent
for (int i = 1; i <= N; i++) {
parent[i] = i;
@@ -40,6 +40,8 @@ int no_of_connected_components() { // To find total no of connected components
// Input your required values: (not hardcoded)
int main() {
std::cin >> N;
parent.resize(N + 1);
siz.resize(N + 1);
make_set();
int edges;
std::cin >> edges; // no of edges in the graph