ContinueLib

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Continue765/ContinueLib

:heavy_check_mark: test/library_checker/tree_lca.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/lca"
#include <common.hpp>
#include "graph/tree/lca.hpp"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    Undigraph<int> g(n);
    for (int v = 1; v < n; ++v) { int p; cin >> p; g.add(p, v); }
    Tree tree(g);
    LCA lca(tree);
    while (q--) { int u, v; cin >> u >> v; cout << lca.get(u, v) << '\n'; }
}
Back to top page