# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58657 | andy627 | 주유소 (KOI16_gas) | C++17 | 915 ms | 2916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#define LL long long
#define pii pair<int,int>
#define pli pair<LL,int>
#define ff first
#define ss second
#define INF (LL)1e18
using namespace std;
int n,m;
pii oil[2555];
vector<pii> edge[2555];
LL dist[2555],ans[2555];
bool is_gone[2555];
priority_queue<pli,vector<pli>,greater<pli> > pq;
void dijkstra(int idx){
for(int i=1;i<=n;i++) is_gone[i]=0;
for(int i=1;i<=n;i++) dist[i]=INF;
dist[oil[idx].ss]=0;
is_gone[oil[idx].ss]=1; pq.push({0,oil[idx].ss});
while(!pq.empty()){
int v=pq.top().ss; pq.pop();
for(int i=0;i<edge[v].size();i++){
if(dist[edge[v][i].ff]>dist[v]+edge[v][i].ss){
dist[edge[v][i].ff]=dist[v]+edge[v][i].ss;
is_gone[edge[v][i].ff]=1;
pq.push({dist[edge[v][i].ff],edge[v][i].ff});
}
}
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&oil[i].ff);
oil[i].ss=i;
}
sort(oil+1,oil+n+1);
while(m--){
int a,b,w;
scanf("%d %d %d",&a,&b,&w);
edge[a].push_back({b,w});
edge[b].push_back({a,w});
}
for(int i=1;i<=n;i++) ans[i]=INF;
ans[1]=0;
bool st=0;
for(int i=n;i>=1;i--){
if(oil[i].ss==1) st=1;
if(!st) continue;
dijkstra(i);
for(int j=1;j<=n;j++){
if(j==oil[i].ss) continue;
ans[j]=min(ans[j],ans[oil[i].ss]+oil[i].ff*dist[j]);
}
}
printf("%lld",ans[n]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |