Recently, I’ve been upsolving the UJGOI 2025 problems, but I couldn’t solve the 4th problem from Day 2. I would be grateful if someone could provide an editorial for the following problem:
You are given a directed graph with $$$n$$$ vertices and $$$m$$$ directed edges ($$$1 \le n, m \le 3 \cdot 10^5$$$), where each edge $$$E_i$$$ is added to the graph at time $$$i$$$ (in order).
There are also $$$Q$$$ online queries of the form $$$(x, y)$$$ ($$$1 \le Q \le 3 \cdot 10^5$$$). For each query, you need to determine the first moment in time when $$$x$$$ and $$$y$$$ belong to the same strongly connected component. If they are never in the same SCC, output -1.




