# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
86573 | tjdgus4384 | 주유소 (KOI16_gas) | C++14 | 57 ms | 52132 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<cstdio>
#include<vector>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<long long, long long> pi;
typedef pair<pair<long long, long long>, long long> ppi;
long long p[2501];
long long dist[2501][2501];
vector<pi> v[2501];
priority_queue<ppi , vector<ppi>, greater<ppi> > pq;
int main()
{
int n, m, a, b, c;
scanf("%d %d", &n, &m);
for(int i = 1;i <= n;i++) scanf("%lld", &p[i]);
for(int i = 0;i < m;i++)
{
scanf("%d %d %d", &a, &b, &c);
v[a].push_back({b, c});
v[b].push_back({a, c});
}
//dijkstra
//(지금까지돈, 도시, 지금까지최소기름값)
pq.push({{0, 1}, p[1]});
memset(dist, -1, sizeof(dist));
while(!pq.empty())
{
long long s = pq.top().first.first;
long long f = pq.top().first.second;
long long t = pq.top().second;
pq.pop();
if(dist[f][t] != -1) continue;
dist[f][t] = s;
if(f == n)
{
printf("%lld", s);
return 0;
}
for(int i = 0;i < v[f].size();i++)
{
if(dist[v[f][i].first][min(t, p[v[f][i].first])] != -1) continue;
pq.push({{s + t * v[f][i].second, v[f][i].first}, min(t, p[v[f][i].first])});
}
}
}
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... |