I am trying to implement Dijkstra’s algorithm to solve a problem for school, but I keep getting the error “Reference to distance is ambiguous”.
Here is my code:
#include <bits/stdc++.h>
using namespace std;
const long MAXN = 100000, MAXM = 400000, MAXL = 50000;
const long long INF = 0x3f3f3f3f;
long N, M, L;
vector<pair<long, long> > adj[MAXN];
vector<long> Q(MAXL);
long distance[MAXN][MAXN];
void Dijkstra(long X){
for(long i = 0; i < N; i++){
distance[X][i] = INF;
}
distance[X][X] = 0;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
scanf("%ld %ld", &N, &M);
long a, b, w;
for(long i = 0; i < N; i++){
scanf("%ld %ld %ld", &a, &b, &w);
adj[a - 1].push_back({b - 1, w});
adj[b - 1].push_back({a - 1, w});
}
scanf("%ld", &L);
for(long i = 0; i < L; i++){
scanf("%ld", &Q[i]);
}
for(long i = 0; i < N; i++){
Dijkstra(i);
}
return 0;
}
The problem appears to be in the function “Dijkstra” whenever there is a refrence to the distance array.
New contributor
NickWasHere is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1