QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#637185#7883. Takeout DeliveringHSTKwowWA 206ms21120kbC++141.2kb2024-10-13 10:48:282024-10-13 10:48:28

Judging History

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

  • [2024-10-13 10:48:28]
  • 评测
  • 测评结果:WA
  • 用时:206ms
  • 内存:21120kb
  • [2024-10-13 10:48:28]
  • 提交

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,w]:g[v]){      //更新距离
                if(dis[x]>d+w){
                    dis[x]=d+w;
                    heap.push({dis[x],x});
                }
            }
        }   
    }
}

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: 2ms
memory: 12104kb

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
Wrong Answer
time: 206ms
memory: 21120kb

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:

1061109567

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '1061109567'