Submission #849501

#TimeUsernameProblemLanguageResultExecution timeMemory
849501TAhmed33Ceste (COCI17_ceste)C++98
160 / 160
415 ms26144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 2e3 + 25; vector <array <int, 3>> adj[MAXN]; int n, m; long long c[MAXN], t[MAXN]; priority_queue <array <int, 3>, vector <array <int, 3>>, greater <array <int, 3>>> pq; signed main () { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b, c, d; cin >> a >> b >> c >> d; adj[a].push_back({b, c, d}); adj[b].push_back({a, c, d}); } for (int i = 2; i <= n; i++) { c[i] = t[i] = 1e16; } pq.push({0, 0, 1}); while (!pq.empty()) { auto k = pq.top(); pq.pop(); c[k[2]] = min(c[k[2]], (int)k[0] * k[1]); if (t[k[2]] < k[1]) continue; t[k[2]] = k[1]; for (auto j : adj[k[2]]) { if (j[1] + k[1] > 4e6) continue; pq.push({k[0] + j[2], k[1] + j[1], j[0]}); } } for (int i = 2; i <= n; i++) { if (c[i] >= 1e16) cout << -1 << '\n'; else cout << c[i] << '\n'; } }
#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...