# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
35802 | moonrabbit2 | 주유소 (KOI16_gas) | C++11 | 1236 ms | 37344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXV 3000
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
struct city
{
int num;
int cost;
};
int v,e,k;
int dist[MAXV][MAXV];
int 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()
{
vector<pair<int,int>>graph[MAXV];
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(pair<int,int>(v-1,w));
graph[v-1].push_back(pair<int,int>(u-1,w));
}
priority_queue<P,vector<P>,greater<P> >PQ;
for(int k=0;k<v;k++){
bool visit[MAXV];
for(int i=0;i<v;i++)
visit[i]=false;
P t;
t.first=0;
t.second=k;
PQ.push(t);
for(int i=0;i<v;i++){
P curr;
while(!PQ.empty()){
curr=PQ.top();
PQ.pop();
if(!visit[curr.second])
break;
}
visit[curr.second]=true;
int ss=graph[curr.second].size();
for(int j=0;j<ss;j++){
if(dist[k][graph[curr.second][j].first]>dist[k][curr.second]+graph[curr.second][j].second){
dist[k][graph[curr.second][j].first]=dist[k][curr.second]+graph[curr.second][j].second;
t.first=dist[k][graph[curr.second][j].first];
t.second=graph[curr.second][j].first;
PQ.push(t);
}
}
}
while(!PQ.empty())
PQ.pop();
}
sort(cities+1,cities+v-1,f);
for(int i=1;i<v;i++){
ans[cities[i].num]=INF;
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("%d",ans[v-1]);
return 0;
}
컴파일 시 표준 에러 (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... |