# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
35804 | 2017-11-30T14:31:02 Z | moonrabbit2 | 주유소 (KOI16_gas) | C++11 | 1186 ms | 37424 KB |
#include <bits/stdc++.h> #define MAXV 3000 #define INF 100000000 using namespace std; typedef pair<int,int> P; struct city { int num; int cost; }; vector<pair<int,int>>graph[MAXV]; int v,e,k; int dist[MAXV][MAXV]; long long ans[MAXV]; city cities[MAXV]; bool f(city a,city b) { if(a.cost==b.cost) return a.num<b.num; return a.cost>b.cost; } int main() { scanf("%d %d",&v,&e); for(int i=0;i<v;i++){ cities[i].num=i; scanf("%d",&cities[i].cost); } for(int i=0;i<v;i++){ for(int j=0;j<v;j++){ if(i!=j) dist[i][j]=INF; } } for(int i=0;i<e;i++){ int u,v,w; scanf("%d %d %d",&u,&v,&w); graph[u-1].push_back(P(v-1,w)); graph[v-1].push_back(P(u-1,w)); } priority_queue<P,vector<P>,greater<P>>PQ; for(int k=0;k<v;k++){ bool visit[MAXV]; PQ.push(P(0,k)); P tp; while(!PQ.empty()){ tp=PQ.top(); PQ.pop(); if(dist[k][tp.second]<tp.first) continue; for(int j=0;j<graph[tp.second].size();j++){ if(dist[k][graph[tp.second][j].first]>dist[k][tp.second]+graph[tp.second][j].second){ dist[k][graph[tp.second][j].first]=dist[k][tp.second]+graph[tp.second][j].second; P t; t.first=dist[k][graph[tp.second][j].first]; t.second=graph[tp.second][j].first; PQ.push(t); } } } } sort(cities+1,cities+v-1,f); for(int i=1;i<v;i++){ ans[cities[i].num]=INF*1000; for(int j=0;j<i;j++){ ans[cities[i].num]=min(ans[cities[i].num],ans[cities[j].num]+dist[cities[j].num][cities[i].num]*cities[j].cost); } } printf("%lld",ans[v-1]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 37292 KB | Output is correct |
2 | Correct | 0 ms | 37292 KB | Output is correct |
3 | Correct | 0 ms | 37292 KB | Output is correct |
4 | Correct | 0 ms | 37292 KB | Output is correct |
5 | Correct | 0 ms | 37292 KB | Output is correct |
6 | Correct | 0 ms | 37292 KB | Output is correct |
7 | Correct | 0 ms | 37292 KB | Output is correct |
8 | Correct | 0 ms | 37292 KB | Output is correct |
9 | Correct | 0 ms | 37292 KB | Output is correct |
10 | Correct | 0 ms | 37292 KB | Output is correct |
11 | Correct | 0 ms | 37292 KB | Output is correct |
12 | Correct | 0 ms | 37292 KB | Output is correct |
13 | Correct | 0 ms | 37292 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 243 ms | 37424 KB | Output is correct |
2 | Incorrect | 269 ms | 37424 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 213 ms | 37424 KB | Output is correct |
2 | Correct | 929 ms | 37424 KB | Output is correct |
3 | Correct | 999 ms | 37424 KB | Output is correct |
4 | Correct | 926 ms | 37424 KB | Output is correct |
5 | Correct | 979 ms | 37424 KB | Output is correct |
6 | Correct | 1186 ms | 37424 KB | Output is correct |
7 | Correct | 1159 ms | 37424 KB | Output is correct |
8 | Correct | 1176 ms | 37424 KB | Output is correct |
9 | Correct | 1016 ms | 37424 KB | Output is correct |
10 | Correct | 969 ms | 37424 KB | Output is correct |
11 | Correct | 959 ms | 37424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 37292 KB | Output is correct |
2 | Correct | 0 ms | 37292 KB | Output is correct |
3 | Correct | 0 ms | 37292 KB | Output is correct |
4 | Correct | 0 ms | 37292 KB | Output is correct |
5 | Correct | 0 ms | 37292 KB | Output is correct |
6 | Correct | 0 ms | 37292 KB | Output is correct |
7 | Correct | 0 ms | 37292 KB | Output is correct |
8 | Correct | 0 ms | 37292 KB | Output is correct |
9 | Correct | 0 ms | 37292 KB | Output is correct |
10 | Correct | 0 ms | 37292 KB | Output is correct |
11 | Correct | 0 ms | 37292 KB | Output is correct |
12 | Correct | 0 ms | 37292 KB | Output is correct |
13 | Correct | 0 ms | 37292 KB | Output is correct |
14 | Incorrect | 13 ms | 37292 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 37292 KB | Output is correct |
2 | Correct | 0 ms | 37292 KB | Output is correct |
3 | Correct | 0 ms | 37292 KB | Output is correct |
4 | Correct | 0 ms | 37292 KB | Output is correct |
5 | Correct | 0 ms | 37292 KB | Output is correct |
6 | Correct | 0 ms | 37292 KB | Output is correct |
7 | Correct | 0 ms | 37292 KB | Output is correct |
8 | Correct | 0 ms | 37292 KB | Output is correct |
9 | Correct | 0 ms | 37292 KB | Output is correct |
10 | Correct | 0 ms | 37292 KB | Output is correct |
11 | Correct | 0 ms | 37292 KB | Output is correct |
12 | Correct | 0 ms | 37292 KB | Output is correct |
13 | Correct | 0 ms | 37292 KB | Output is correct |
14 | Correct | 243 ms | 37424 KB | Output is correct |
15 | Incorrect | 269 ms | 37424 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |