CSES Flight Routes

Author: Benjamin Qi

Table of Contents


Edit on Github

Time Complexity: O(mklog(mk))\mathcal{O}(mk\log (mk))

Maintain a priority queue of the kk best distances found for each vertex. We'll iterate through the adjacency list of each vertex at most kk times.

int n,m,k;
priority_queue<ll> bes[MX];
vector<pii> adj[MX];
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
F0R(i,m) {
int a,b,c; cin >> a >> b >> c;

Give Us Feedback on CSES Flight Routes!