Submission #269791

#TimeUsernameProblemLanguageResultExecution timeMemory
269791sean9892주유소 (KOI16_gas)C++14
100 / 100
122 ms50336 KiB
#include<bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; using dat=pair<ll,pii>; #define fi first #define se second vector<pii> g[2510]; int cst[2510]; ll dst[2510][2510]; int main(void){ ios::sync_with_stdio(0);cin.tie(0); int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>cst[i]; } for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; g[a].emplace_back(b,c); g[b].emplace_back(a,c); } memset(dst,0x3f,sizeof(dst)); dst[1][cst[1]]=0; priority_queue<dat> q; ll res=0x3f3f3f3f3f3f3f3f; #define pushDat(d,x,c) q.push(dat(-(d),pii(x,c))) #define popDat(d,x,c) do{d=-q.top().fi;x=q.top().se.fi;c=q.top().se.se;q.pop();}while(0) pushDat(0,1,cst[1]); while(!q.empty()){ ll d; int x,c; popDat(d,x,c); if(dst[x][c]<d)continue; if(x==n){ res=min(res,d); } for(auto& e:g[x]){ int i,w; tie(i,w)=e; if(dst[i][min(c,cst[i])]>d+c*w){ dst[i][min(c,cst[i])]=d+c*w; pushDat(d+c*w,i,min(c,cst[i])); } } } #undef pushDat #undef popDat cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...