QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637180 | #7883. Takeout Delivering | HSTKwow | RE | 0ms | 11804kb | C++14 | 1.2kb | 2024-10-13 10:41:52 | 2024-10-13 10:41:53 |
Judging History
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 ...