Блог пользователя i_love_sqrt_decomp

Автор i_love_sqrt_decomp, история, 18 месяцев назад, По-английски

Is there an algorithm that solves this problem for any $$$k$$$? https://codeforces.me/problemset/gymProblem/101806/X.

Any complexity is allowed, if it solves the problem for $$$k\leq5$$$ with the original constraints.

Spoiler
  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
18 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can't we just check all the simple paths of length K emerging from the vertex 1 and ending at the Vertex n. Since k <= 5, I think this should pass for n and m even going upto 1e6.

Please correct me if I am wrong.

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Consider a graph where the edges are split into 5 layers, with the first layer being $$$1$$$, second layer $$$2$$$ to $$$\frac{n}{2}-1$$$, third layer $$$\frac{n}{2}$$$, fourth layer $$$\frac{n}{2}+1$$$ to $$$n-1$$$, fifth layer $$$n$$$, and edges between all pairs of vertices in consecutive layers. There would be $$$O(n^2)$$$ possible paths from $$$1$$$ to $$$n$$$, all length $$$4$$$.