Editorial for AYJCC24 P6 - Wandering Walk
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
This problem requires basic knowledge of graphs to solve.
Subtask 1 [30%]
This subtask was intended for brute force. By doing any elementary graph searching algorithm (depth first search or breadth first search), one can mark any edges visited and take their bitwise OR for each query.
Time Complexity: \(O(Q(N + M))\)
Subtask 2 [70%]
We can make the observation that we can travel along every edge directly or indirectly connected to some starting node. As such, we split the graph into components, where a component consists of the nodes and edges that are all indirectly connected, and for each component, store the bitwise OR of its edges. For each query, simply check which component the start and end nodes are in.
Time Complexity: \(O(N + M + Q)\)
Comments