Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
150033 陈志恒 最小交通费用问题 C++ 通过 100 1 MS 2600 KB 777 2024-06-01 14:39:10

Tests(5/5):


#include<bits/stdc++.h> using namespace std; using pil=pair<int,int>; vector<pil> g[100000]; long long d[100000],s,n,m,c,c1,s1,t; void dij(){ for(int i=0;i<=n;i++){ d[i]=2147483647; } d[s]=0; priority_queue<pil,vector<pil>,greater<pil> > minq; minq.push(pil{d[s],s}); while(!minq.empty()){ auto x=minq.top();minq.pop(); long long du=x.first,u=x.second; if(du>d[u]) continue; for(auto e:g[u]){ int v=e.first,w=e.second; if(d[v]>du+w){ d[v]=du+w; minq.push(pil{d[v],v}); } } } } int main(){ cin>>n>>m; for(int i=1;i<=m;i++){ int u,v,w; cin>>u>>v>>w; g[u].push_back(pil{v,w}); } cin>>s>>s1; dij(); c=d[s1]; t=s; s=s1; dij(); // cout<<c<<" "<<c1<<endl; c1=d[t]; cout<<c+c1; return 0; }


测评信息: