Editorial for TLE '15 P6 - Rock, Paper, Scissors
Submitting an official solution before solving the problem yourself is a bannable offence.
For the 20% test case, we can generate a 2D array representing if a node can directly or indirectly beat another node. After, for each query, generate all possible subsets, check each subset to see if it is valid, and output the size of the greatest valid subset.
In order to get 100% of the points:
First, use Tarjan's Strongly Connected Components algorithm to group all nodes that are strongly connected. Then, run a DFS to check which components are better than others. Notice that the MEV between two components (and thus between nodes in those two components) is the largest number of nodes in a path between two components. Thus, we can use dynamic programming on the SCC (strongly connected components) DAG (directed acyclic graph) to determine the MEV between any two components and answer queries in constant time. The DP can be done during the DFS after Tarjan's SCC algorithm.
Time complexity:
Comments
What's the faster way to compute the longest path between any 2 nodes on a DAG?
I've searched on google that there's a solution using topological sorting. Do I need that or there's an easier way?
This problem doesn't ask for the longest path between any 2 nodes on a DAG.