CSES - Game Routes

Author: Andrew Wang

Table of Contents


Edit on Github

Time Complexity:

This problem is very similar to the "Longest Flight Route" problem discussed earlier in this module. Let denote the number of paths reaching . We can see,

with an exception of , or the starting node, having a value of 1. We process the nodes topologically so will already have been computed before .

1#include <iostream>
2#include <vector>
3#include <queue>
4using namespace std;
5int n;
6vector<int> edge[100001];
7vector<int> backedge[100001];
8
9int main(){
10 ios_base::sync_with_stdio(0); cin.tie(0);

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 - Game Routes!