following the code:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n[20];
class State{
public:
int pos,val;
State(int pos, int val){
this->pos = pos;
this->val = val;
}
bool operator<(State const &s) &{
return this->val > s.val;
}
};
void dijstra(vector<pair<int,int> > &v){
priority_queue<State> pq;
pq.push(State(1,0));
while(!pq.empty()){
State tmp = pq.top();
pq.pop();
int now = tmp.pos;
int val = tmp.val;
for(int i = 0; i < v[now].size(); i++){ // this error point
int next = v[now][i].fisrt;
int nextval = v[now][i].second;
if(nextval + value < n[next]){
n[next] = nextval + val;
pq.push(State(next,nextval+val));
}
}
}
}
int main() {
int n,m,a,b,c;
scanf("%d %d",&n,&m);
vector<pair<int,int> > v[n];
for(int i = 0; i < m; i++){
scanf("%d %d %d",&a,&b,&c);
v[a].push_back({b,c});
}
for(int i = 1; i <= n; i++){
n[i] = 2147000000;
}
n[0] = 0;
DFS(v);
for(int i = 2; i <= n; i++){
printf("%d : %d\n",i,arr[i]);
}
return 0;
}
This code is dijstra algorithm. this point has error in dijstra function. [Error] '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type' has no member named 'size' I'm not sure what is the error. Why can't I use v[now].size()? If I use a pair in a vector, does size() function not work?