CSES - Investigation

Author: Andrew Wang

Table of Contents


Edit on Github

Time Complexity:

We can run Dijkstra keeping track of the distance: , the number of ways with the minimum distance: , the minimum flights with the minimum distance: , and the maximum flights with the minimum distance: . For every node, , we take into consideration all of its neighbors, . If we can reach in a shorter distance than its current minimum, we update the distance and reset , , and . We also have to take into consideration if we can reach in an equivalent distance. If so, we update:

1#include <bits/stdc++.h>
2using namespace std;
3
4typedef long long ll;
5vector<pair<ll, int>> edge[100001];
6ll dist[100001]; ll num[100001];
7int minf[100001];int maxf[100001];
8bool v[100001];
9ll MAX = 1000000000000000L; ll MOD = 1000000007L;
10void djikstra(int s){

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on CSES - Investigation!