cp-library

競技プログラミング用 C++ ライブラリ

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/auxiliary_tree.test.cpp

test/auxiliary_tree.test.cpp · GitHub で見る

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.yosupo.jp/problem/lca"
#include "../tree/auxiliary_tree.hpp"
#include "../tree/lca.hpp"
#include "../components/fast_io.hpp"
#include <array>

int main() {
	FastInput in;
	FastOutput out;
	int n = 0, q = 0;
	in.read(n), in.read(q);
	LCA tree(n);
	for (int v = 1; v < n; ++v) {
		int p = 0;
		in.read(p);
		tree.add_edge(p, v);
	}
	tree.build();
	AuxiliaryTree vt(tree);
	while (q--) {
		std::array<int, 2> keys{};
		in.read(keys[0]), in.read(keys[1]);
		vt.build(keys);
		out.println(vt[vt.root()].vertex);
	}
}
Back to top page