competitive-programming-java-library

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

View the Project on GitHub shun0923/competitive-programming-java-library

:heavy_check_mark: library/Lca.java

Depends on

Verified with

Code

package library;

import java.util.*;
import library.FastIO;
import library.AbstractGraph;

final class Lca {
	private final int numNode;
	private Doubling db;
	public final int depth[];

	// O(VlogV)
	public <Edge extends AbstractEdge<Edge>> Lca(final AbstractGraph<? extends AbstractNode<Edge>, Edge> g, final int root) { this(g.numNode, g.nodes(), root); }
	public <Edge extends AbstractEdge<Edge>> Lca(final int numNode, final AbstractNode<Edge>[] nodes, final int root) {
		FastIO.nonNegativeCheck(numNode);
		FastIO.rangeCheck(root, numNode);
		this.numNode = numNode;
		depth = new int[numNode];
		db = new Doubling(numNode, numNode, bfs(root, nodes));
	}

	private final <Edge extends AbstractEdge<Edge>> int[] bfs(final int start, final AbstractNode<Edge>[] nodes) { // O(V)
		int edges[] = new int[numNode];
		int stack[] = new int[numNode];
		int ptr = 0;
		int size = 0;

		Arrays.fill(depth, -1);
		depth[start] = 0;
		edges[start] = -1;
		depth[start] = 0;
		stack[size ++] = 0;
		while(ptr != size) {
			int crt = stack[ptr ++];
			for(Edge e : nodes[crt]) {
				if(depth[e.target] == -1) {
					depth[e.target] = depth[crt] + 1;
					edges[e.target] = crt;
					stack[size ++] = e.target;
				}
			}
		}
		return edges;
	}

	public final int cal(int u, int v) { // O(logV)
		FastIO.rangeCheck(u, numNode);
		FastIO.rangeCheck(v, numNode);
		if(depth[u] > depth[v]) {
			int tmp = u;
			u = v;
			v = tmp;
		}
		for(int k = 0; k < db.log; k ++) {
			if((depth[v] - depth[u] & 1 << k) != 0) v = db.next[k][v];
		}
		for(int k = db.log - 1; k >= 0; k --) {
			if(u != v && db.next[k][u] != db.next[k][v]) {
				u = db.next[k][u];
				v = db.next[k][v];
			}
		}
		if(u != v) {
			u = db.next[0][u];
			v = db.next[0][v];
		}
		return u;
	}
}
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/user_defined.py", line 71, in bundle
    return subprocess.check_output(shlex.split(command))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.
Back to top page