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 - 如何在C中清除控制台而不闪烁
- python - 使用 python 从 Cassandra 数据库中检索数据
- database - 我可以为 MongoDB 索引配置特定路径吗?
- html - 如何对齐网格系统html/css?
- docker - 无法到达 docker 容器 - 端口未绑定
- html - 响应式列,防止孩子在折叠时在列之间移动
- javascript - 在 mapbox 中读取 GPX 文件或第三方 URL 以添加行
- python - 为什么这个带有浮点除法的 Django 查询注释这么慢?
- android - java.lang.IllegalStateException: WorkManager 已经初始化。即使工作管理器未初始化
- google-pay - 在 Google 支付网关中没有可用于此商家的可接受的卡