I am using vector<pair<int,int> > ar[100000];
and I have to use it for several test cases where every time I want it to initialize but I am getting segmentation fault for this.
I tried it with declaring inside the test case loop and globally. its running fine for the first test case or if there is only one test case.
I also tried to delete the vector after every test case but I don't know the exact syntax of deleting a vector of this type, any help ??
int main() {
long long a, b, c, d = 0, i, j, n, m, t;
scanf("%lld", &t);
while (t--) {
scanf("%lld %lld", &n, &m);
vector<pair<long long, long long> > ar[n + 9];
for(i = 0; i < m; i++) {
scanf("%lld %lld %lld",&a,&b,&c);
ar[a - 1].push_back(make_pair(b - 1, c));
ar[b - 1].push_back(make_pair(a - 1, c));
}
vector<long long> distance(10000, 100000000);
scanf("%lld", &a);
dijkstra(ar, a - 1, distance);
for (i = 0; i < n; i++) {
if (i == a - 1)
continue;
if (distance[i] != 100000000)
printf("%lld ", distance[i]);
else {
// printf("%lld\n", visited[i]);
printf("-1 ");
}
}
printf("\n");
// ar.clear();
distance.clear();
}
return 0;
}