MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / query

Method query

code/graph/hld.test.cpp:46–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 // }
45
46 int query(int u, int v) {
47 // int l = lca(u, v);
48 // return f(query_upto(u, l), query_upto(v, l));
49
50 vector<bool> visited(n, false);
51 stack<ii> S;
52 S.push(ii(u, ID));
53 visited[u] = true;
54
55 while (!S.empty())
56 {
57 ii cur = S.top(); S.pop();
58 // printf("%d\n", cur.first);
59
60 if (cur.first == v)
61 return cur.second;
62
63 for (int i = 0; i < size(adj[cur.first]); i++)
64 {
65 int nxt = adj[cur.first][i].first;
66 if (!visited[nxt])
67 {
68 visited[nxt] = true;
69 S.push(ii(nxt, f(cur.second, adj[cur.first][i].second)));
70 }
71 }
72 }
73
74 assert(false);
75 }
76};
77
78void test() {

Callers 1

testFunction · 0.45

Calls 5

fFunction · 0.85
pushMethod · 0.45
emptyMethod · 0.45
topMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected