QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#637180#7883. Takeout DeliveringHSTKwowRE 0ms11804kbC++141.2kb2024-10-13 10:41:522024-10-13 10:41:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 10:41:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:11804kb
  • [2024-10-13 10:41:52]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;


//Dijkstra求最短路 II
//https://www.acwing.com/problem/content/852/

typedef pair<int,int> PII;
const int N=3e5+10,INF=0x3f3f3f3f;
vector<pair<int,int>>g[N];
int dis[N],vis[N];

void add(int a,int b,int c){
    g[a].push_back({b,c});
    g[b].push_back({a,c});
}

void dijkstra(){
    memset(dis,0x3f,sizeof dis);
    dis[1]=0;
    priority_queue<PII,vector<PII>,greater<PII>> heap;
    heap.push({0,1});       //路径长度和节点

    while(heap.size()){
        PII t=heap.top();           //找到距离最小的点
        heap.pop();
        int v=t.second,d=t.first;   //起点到v的距离
        if(!vis[v]){                //没加入最短路的点
            vis[v]=1;
            for(auto [x,y]:g[v]){      //更新距离
                if(dis[x]>d+y){
                    dis[x]=d+y;
                    heap.push({dis[x],y});
                }
            }
        }   
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        add(a,b,c);
    }

    dijkstra();
    cout<<dis[n]<<endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11804kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Runtime Error

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:


result: