Submission #147851

#TimeUsernameProblemLanguageResultExecution timeMemory
147851luciocfCeste (COCI17_ceste)C++14
160 / 160
675 ms25368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pii; const int maxn = 2e3+10; const int maxv = 1e6+10; const ll inf = 1e18+10; int n; int last[maxn]; ll ans[maxn]; vector<pair<pii, int>> grafo[maxn]; void dijkstra(void) { for (int i = 1; i < maxn; i++) ans[i] = inf, last[i] = maxv; priority_queue<pair<pii, int>, vector<pair<pii, int>>, greater<pair<pii, int>>> fila; fila.push({{0, 0}, 1}), ans[1] = 0, last[1] = 0; while (!fila.empty()) { int u = fila.top().second; int sum_c = fila.top().first.first, sum_t = fila.top().first.second; fila.pop(); if (last[u] < sum_t) continue; last[u] = sum_t; ans[u] = min(ans[u], 1ll*sum_t*sum_c); for (auto pp: grafo[u]) { int v = pp.second; int t = pp.first.second, c = pp.first.first; if (sum_t+t > maxv || sum_c+c > maxv) continue; fila.push({{sum_c+c, sum_t+t}, v}); } } } int main(void) { int m; scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { int u, v, t, c; scanf("%d %d %d %d", &u, &v, &t, &c); grafo[u].push_back({{c, t}, v}); grafo[v].push_back({{c, t}, u}); } dijkstra(); for (int i = 2; i <= n; i++) { if (ans[i] == inf) printf("-1\n"); else printf("%lld\n", ans[i]); } }

Compilation message (stderr)

ceste.cpp: In function 'int main()':
ceste.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
ceste.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &u, &v, &t, &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...
#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...