108. Rooted.virtual returns a virtual tree over a fresh domain (2026-11-21)
- Decision.
t.virtual(keys)replacest.virtual_tree(keys). It returnsVirtualTree<V, K>whose own domainvt.Klists the kept vertices (keys and pairwise LCAs) in preorder, withat: [K]V,up: [K]?K,len: [K]Int(weighted distance toup) andkey: [K]Bool. A per-query DP is thenvar dp: [vt.K]Int = 0andfor x in vt.K.rev, children first, with no[V]scratch to reset and no edge list to turn back into parents. Matched C++ (bench/trees/virtual_bench): 1.12x and 1.18x at n = 2·10^5, q = 10^5, k = 10; 0.9x at n = 10^6, k = 1000. - Reverse. Restore
virtual_treereturning(nodes, edges)from history; callers rebuild parents from the edges.