# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
56961 | red1108 | 주유소 (KOI16_gas) | C++17 | 1589 ms | 52884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define P pair<long long int,long long int>
using namespace std;
typedef long long ll;
ll n,m;
ll cost[2510];
bool visit[2510];
ll dis[2510][2510];
vector<ll> graph[2510],dist[2510];
priority_queue<P,vector<P>, greater<P> >pq;
P now;
int main()
{
ll i, j;
ll a,b,c;
scanf("%lld %lld", &n, &m);
for(i=1;i<=n;i++) scanf("%lld", &cost[i]);
for(i=1;i<=m;i++)
{
scanf("%lld %lld %lld", &a, &b, &c);
graph[a].push_back(b);
graph[b].push_back(a);
dist[a].push_back(c);
dist[b].push_back(c);
}
for(i=1;i<=n;i++)
{
while(!pq.empty()) pq.pop();
fill(visit+1,visit+n+1,0);
pq.push({0,i});
while(!pq.empty())
{
now=pq.top();
pq.pop();
if(visit[now.second]) continue;
visit[now.second]=1;
for(int to=0;to<graph[now.second].size();to++)
{
if((dis[i][graph[now.second][to]]==0||dis[i][graph[now.second][to]]>now.first+dist[now.second][to])&&graph[now.second][to]!=i)
{
dis[i][graph[now.second][to]]=now.first+dist[now.second][to];
pq.push({now.first+dist[now.second][to],graph[now.second][to]});
}
}
}
for(j=1;j<=n;j++)
{
dis[i][j]*=cost[i];
}
}
while(!pq.empty()) pq.pop();
fill(visit+1,visit+n+1,0);
pq.push({0,1});
for(i=2;i<=n;i++)
{
pq.push({dis[1][i],i});
}
while(!pq.empty())
{
now=pq.top();
pq.pop();
if(visit[now.second]) continue;
visit[now.second]=1;
for(i=2;i<=n;i++)
{
if(dis[1][i]>now.first+dis[now.second][i])
{
dis[1][i]=now.first+dis[now.second][i];
pq.push({now.first+dis[now.second][i],(ll)i});
}
}
}
printf("%lld", dis[1][n]);
}
컴파일 시 표준 에러 (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... |