Submission #86573

#TimeUsernameProblemLanguageResultExecution timeMemory
86573tjdgus4384주유소 (KOI16_gas)C++14
100 / 100
57 ms52132 KiB
#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)

gas.cpp: In function 'int main()':
gas.cpp:42:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i < v[f].size();i++)
                       ~~^~~~~~~~~~~~~
gas.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
gas.cpp:18:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i <= n;i++) scanf("%lld", &p[i]);
                               ~~~~~^~~~~~~~~~~~~~~
gas.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...