> >,c++"/>

首页 > 解决方案 > 有什么问题 ?[错误] '__gnu_cxx::__alloc_traits> >

问题描述

遵循代码:

#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;
}

这段代码是 dijstra 算法。这一点在 dijstra 函数中有错误。[错误] '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type' 没有名为 'size' 的成员我不确定是什么错误。为什么我不能使用 v[now].size()?如果我在向量中使用一对,size() 函数不起作用吗?

标签: c++

解决方案


推荐阅读