Submission #333673

#TimeUsernameProblemLanguageResultExecution timeMemory
333673ncduy0303Ferries (NOI13_ferries)C++17
40 / 40
326 ms19556 KiB
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; int n, m; vector<int> adj[MAX_N]; priority_queue<int> cost[MAX_N]; vector<ll> dist; void dijk(int s) { dist.assign(n + 1, LINF); priority_queue<ar<ll,2>, vector<ar<ll,2>>, greater<ar<ll,2>>> pq; dist[s] = 0; pq.push({0, s}); while (pq.size()) { auto [d, u] = pq.top(); pq.pop(); if (d > dist[u]) continue; for (auto v : adj[u]) { int w = cost[v].top(); cost[v].pop(); if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; pq.push({dist[v], v}); } } } } void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; adj[v].push_back(u); cost[u].push(w); } dijk(n); cout << dist[1] << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...