Editorial for WOSS Dual Olympiad 2023 S3: Flying
                Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
                Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
To solve the first subtask, let  be either 0 or 1, representing if we can reach node 
 with a path of exactly 
 in length. 
Use BFS to calculate all the states, then answer queries in constant time. Time complexity: 
.
Let  be the length of any edge attached to node 1. If we can reach node 
 with a path of length exactly 
, we can also reach node 
 with paths of lengths (
), (
), (
).
Thus, let  be the minimum distance required to reach node 
 such that 
. This can be computed using Dijkstra. Then for each query (
, 
), check if 
. If the statement is false then it is obviously not possible. If it is true then 
 can be written as 
, so it is possible. Time complexity: 
.
Comments
I don't understand why the edge (
) has to be directly attached to 1
because otherwise you'll have to traverse some other edges to reach the edge k, where as if it's attached to 1, you can add 2k freely.
thx but what if the edge you have to traverse twice is not directly connected to node 1 how would that work?