Witam. Proszę o pomoc z poniższym programem. Program jest przepisany z pseudokodu z książki Cormena, ale pojawia się błąd przy wywołaniu make_set (segmentation fault). Gdzie szukać przyczyny?
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <sstream>
#include <vector>
using namespace std;
vector<int> ojciec, ranga;
void make_set (int x)
{
ojciec[x] = x;
ranga[x] = 0;
}
int find_set (int x)
{
if (x != ojciec[x])
ojciec[x] = find_set(ojciec[x]);
return ojciec[x];
}
void link (int x, int y)
{
if (ranga[x] > ranga[y])
ojciec[y] = x;
else
{
ojciec[x] = y;
if (ranga[x] == ranga[y])
++ranga[y];
}
}
void join_set (int x, int y)
{
link(find_set(x), find_set(y));
}
int main () {
int n;
int k;
int v1, v2;
ifstream fin("in.txt");
fin >> n;
for(int a=1; a<n; a++) {
make_set(a);
}
fin >> k;
for(int i=1; i<k+1; i++) {
fin >> v1 >> v2;
}
return 0;
}
Bardzo proszę o wskazówki! Pozdrawiam serdecznie.