公式

F - SQL 解説 by sorohue


Let’s construct a graph by treating each query as a vertex and creating a single unidirectional reference edge extending from each query that outputs data.

If you follow the reference edges, you will inevitably reach either a cycle in the reference edges or a query that outputs data.

All queries connected by an edge must have the same output. - If there is a query that outputs the input, unify the output to that input. - If there is a cycle in the reference edges (i.e., no query that outputs the input), it is acceptable to unify the output to any value within the range.

You may use any algorithm—DFS, BFS, or DSU—for cycle detection and component determination. The total time complexity is \({\cal O}(N)\).

投稿日時:
最終更新: