MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / path_intersection

Function path_intersection

Graph Theory/Path Intersection.cpp:68–79  ·  view source on GitHub ↗

returns the intersection of two paths (a,b) and (c,d) {0,0} for null path

Source from the content-addressed store, hash-verified

66// returns the intersection of two paths (a,b) and (c,d)
67// {0,0} for null path
68pair<int, int> path_intersection(int a, int b, int c, int d) {
69 if (a == 0 || b == 0) return {0, 0};
70 int u = lca(a, b), v = lca(c, d); // splits both paths in two chains from lca to one node
71 pair<int, int> x, y;
72 x = getCommonPath(u, a, v, c);
73 y = getCommonPath(u, a, v, d);
74 pair<int, int> a1 = path_union_light(x, y);
75 x = getCommonPath(u, b, v, c);
76 y = getCommonPath(u, b, v, d);
77 pair<int, int> a2 = path_union_light(x, y);
78 return path_union_light(a1, a2);
79}
80int32_t main() {
81 int t, cs = 0; cin >> t;
82 while (t--) {

Callers 1

mainFunction · 0.85

Calls 3

getCommonPathFunction · 0.85
path_union_lightFunction · 0.85
lcaFunction · 0.70

Tested by

no test coverage detected