diff --git a/src/1-ds/ds_segtree.cpp b/src/1-ds/ds_segtree.cpp index 39644e4..ce605c3 100644 --- a/src/1-ds/ds_segtree.cpp +++ b/src/1-ds/ds_segtree.cpp @@ -235,8 +235,8 @@ struct seg_2d { // 1-indexed // what: 2D segment tree with coordinate compression for sparse updates/queries. // time: prep O(q log q), update/query O(log^2 n); memory: O(q log q) -// constraint: x is 1-indexed [1..n]; y is coordinate value; call mark_set/mark_qry first, then prep, then set/query. -// usage: seg2d_comp st(n); st.mark_set(x, y); st.mark_qry(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2); +// constraint: x is 1-indexed [1..n]; y is coordinate value; call mark_set/mark_query first, then prep, then set/query. +// usage: seg2d_comp st(n); st.mark_set(x, y); st.mark_query(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2); struct seg2d_comp { // x: 1-indexed int n; vector> a; @@ -247,7 +247,7 @@ struct seg2d_comp { // x: 1-indexed // goal: record y-coordinates that will be updated. for (x += n - 1; x >= 1; x >>= 1) used[x].push_back(y); } - void mark_qry(int x1, int x2, int y1, int y2) { + void mark_query(int x1, int x2, int y1, int y2) { // goal: record y-coordinates needed for queries. for (x1 += n - 1, x2 += n; x1 < x2; x1 >>= 1, x2 >>= 1) { if (x1 & 1) { diff --git a/src/2-graph/cc_bcc.cpp b/src/2-graph/cc_bcc.cpp index 663325f..babfd25 100644 --- a/src/2-graph/cc_bcc.cpp +++ b/src/2-graph/cc_bcc.cpp @@ -3,7 +3,7 @@ // what: find biconnected components and articulation points/bridges in an undirected graph. // time: O(n+m); memory: O(n+m) // constraint: 1-indexed; no self-loops; recursion depth O(n). -// usage: bcc_graph g; g.init(n); g.add(u,v); g.run(); // g.bccs, g.ap, g.ae +// usage: bcc_graph g; g.init(n); g.add_edge(u,v); g.run(); // g.bccs, g.ap, g.ae struct bcc_graph { int n, tim; vector> adj; @@ -23,7 +23,7 @@ struct bcc_graph { ed.clear(); bccs.clear(); } - void add(int u, int v) { + void add_edge(int u, int v) { int id = sz(ed); ed.push_back({u, v}); adj[u].push_back({v, id}); diff --git a/src/2-graph/cc_scc.cpp b/src/2-graph/cc_scc.cpp index 492e584..66428fd 100644 --- a/src/2-graph/cc_scc.cpp +++ b/src/2-graph/cc_scc.cpp @@ -3,7 +3,7 @@ // what: compute SCCs in a directed graph using Kosaraju's algorithm. // time: O(n+m); memory: O(n+m) // constraint: directed; 1-indexed; recursion depth O(n). -// usage: scc_kosa s; s.init(n); s.add(u,v); int c=s.run(); +// usage: scc_kosa s; s.init(n); s.add_edge(u,v); int c=s.run(); struct scc_kosa { int n; vector> g, rg, sccs; @@ -18,7 +18,7 @@ struct scc_kosa { comp.assign(n + 1, -1); ord.clear(); } - void add(int u, int v) { + void add_edge(int u, int v) { g[u].push_back(v); rg[v].push_back(u); } @@ -50,7 +50,7 @@ struct scc_kosa { // what: compute SCCs in a directed graph using Tarjan's algorithm. // time: O(n+m); memory: O(n+m) // constraint: directed; 1-indexed; recursion depth O(n). -// usage: scc_tarjan s; s.init(n); s.add(u,v); int c=s.run(); +// usage: scc_tarjan s; s.init(n); s.add_edge(u,v); int c=s.run(); struct scc_tarjan { int n, tim; vector> g, sccs; @@ -67,7 +67,7 @@ struct scc_tarjan { ins.assign(n + 1, 0); st.clear(); } - void add(int u, int v) { g[u].push_back(v); } + void add_edge(int u, int v) { g[u].push_back(v); } void dfs(int v) { dfn[v] = low[v] = ++tim; st.push_back(v); diff --git a/src/2-graph/euler_circ.cpp b/src/2-graph/euler_circ.cpp index f1d944a..d70060a 100644 --- a/src/2-graph/euler_circ.cpp +++ b/src/2-graph/euler_circ.cpp @@ -3,7 +3,7 @@ // what: build an Eulerian circuit in an undirected multigraph (adjacency matrix). // time: O(n^2+m); memory: O(n^2) // constraint: 1-indexed; all nonzero-degree nodes connected. -// usage: euler_cir g; g.init(n); g.add(u,v); if (g.can()) auto path=g.run(1); +// usage: euler_cir g; g.init(n); g.add_edge(u,v); if (g.can()) auto path=g.run(1); struct euler_cir { int n; vector> adj; @@ -16,7 +16,7 @@ struct euler_cir { nxt.assign(n + 1, 1); path.clear(); } - void add(int u, int v, int c = 1) { + void add_edge(int u, int v, int c = 1) { // goal: add c parallel edges between u and v. if (u == v) adj[u][u] += 2 * c; else adj[u][v] += c, adj[v][u] += c; diff --git a/src/2-graph/sp_basic.cpp b/src/2-graph/sp_basic.cpp index a68946d..ecc7b24 100644 --- a/src/2-graph/sp_basic.cpp +++ b/src/2-graph/sp_basic.cpp @@ -3,7 +3,7 @@ // what: compute single-source shortest paths with non-negative edges (Dijkstra). // time: O((n+m)log n); memory: O(n+m) // constraint: directed; 1-indexed; w >= 0. -// usage: dijkstra g; g.init(n); g.add(u,v,w); auto dist=g.run(s); +// usage: dijkstra g; g.init(n); g.add_edge(u,v,w); auto dist=g.run(s); struct dijkstra { static const ll INF = (1LL << 62); int n; @@ -14,7 +14,7 @@ struct dijkstra { n = n_; adj.assign(n + 1, {}); } - void add(int u, int v, ll w) { adj[u].push_back({w, v}); } + void add_edge(int u, int v, ll w) { adj[u].push_back({w, v}); } vector run(int s) { // result: dist[i] = shortest distance from s to i. vector dist(n + 1, INF); @@ -39,7 +39,7 @@ struct dijkstra { // what: compute single-source shortest paths with possible negative edges. // time: O(nm); memory: O(n+m) // constraint: directed; 1-indexed; detects negative cycle reachable from s. -// usage: bell_ford g; g.init(n); g.add(u,v,w); bool ok=g.run(s, dist); +// usage: bell_ford g; g.init(n); g.add_edge(u,v,w); bool ok=g.run(s, dist); struct bell_ford { static const ll INF = (1LL << 62); int n; @@ -50,7 +50,7 @@ struct bell_ford { n = n_; ed.clear(); } - void add(int u, int v, ll w) { ed.push_back({u, v, w}); } + void add_edge(int u, int v, ll w) { ed.push_back({u, v, w}); } bool run(int s, vector &dist) { // result: false if a negative cycle is reachable. dist.assign(n + 1, INF); @@ -74,7 +74,7 @@ struct bell_ford { // what: compute all-pairs shortest paths with dynamic programming. // time: O(n^3); memory: O(n^2) // constraint: directed; 1-indexed; watch overflow on INF. -// usage: floyd g; g.init(n); g.add(u,v,w); g.run(); auto &d=g.d; +// usage: floyd g; g.init(n); g.add_edge(u,v,w); g.run(); auto &d=g.d; struct floyd { static const ll INF = (1LL << 62); int n; @@ -86,7 +86,7 @@ struct floyd { d.assign(n + 1, vector(n + 1, INF)); for (int i = 1; i <= n; i++) d[i][i] = 0; } - void add(int u, int v, ll w) { d[u][v] = min(d[u][v], w); } + void add_edge(int u, int v, ll w) { d[u][v] = min(d[u][v], w); } void run() { // goal: relax all pairs via intermediate nodes. for (int k = 1; k <= n; k++) { diff --git a/src/2-graph/sp_kth.cpp b/src/2-graph/sp_kth.cpp index 6738fbb..a808181 100644 --- a/src/2-graph/sp_kth.cpp +++ b/src/2-graph/sp_kth.cpp @@ -3,7 +3,7 @@ // what: enumerate k-th shortest walk from s to t with non-negative weights (Eppstein-style). // time: O((n+m)log m + klog k); memory: O(n+m+heap) // constraint: 1-indexed; w >= 0; n <= MAXN-1; recursion depth O(log m). -// usage: kth_walk g; g.init(n); g.add(u,v,w); auto v=g.run(s,e,k); +// usage: kth_walk g; g.init(n); g.add_edge(u,v,w); auto v=g.run(s,e,k); struct kth_walk { static const int MAXN = 303030; static const ll INF = (ll)1e18; @@ -42,7 +42,7 @@ struct kth_walk { for (int i = 1; i <= n; i++) g[i].clear(), rg[i].clear(); hp.init(); } - void add(int u, int v, ll w) { + void add_edge(int u, int v, ll w) { g[u].push_back({w, v}); rg[v].push_back({w, u}); } diff --git a/src/3-tree/lca_sparse.cpp b/src/3-tree/lca_sparse.cpp index 394ae24..198342b 100644 --- a/src/3-tree/lca_sparse.cpp +++ b/src/3-tree/lca_sparse.cpp @@ -3,7 +3,7 @@ // what: LCA via binary lifting for rooted tree. // time: build O(n log n), query O(log n); memory: O(n log n) // constraint: 1-indexed tree. -// usage: lca_sparse l; l.init(n); l.add(u,v); l.build(1); int w=l.lca(u,v); +// usage: lca_sparse l; l.init(n); l.add_edge(u,v); l.build(1); int w=l.lca(u,v); struct lca_sparse { int n, lg; vector> adj, up; @@ -17,7 +17,7 @@ struct lca_sparse { up.assign(lg, vector(n + 1, 0)); dep.assign(n + 1, 0); } - void add(int u, int v) { + void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } diff --git a/src/3-tree/tree_centroid.cpp b/src/3-tree/tree_centroid.cpp index 62e6da9..34e3202 100644 --- a/src/3-tree/tree_centroid.cpp +++ b/src/3-tree/tree_centroid.cpp @@ -3,7 +3,7 @@ // what: centroid decomposition for tree, builds centroid parent/children for path queries. // time: O(n log n); memory: O(n) // constraint: 1-indexed tree. -// usage: cen_decomp cd; cd.init(n); cd.add(u,v); cd.build(); int p=cd.par[v]; +// usage: cen_decomp cd; cd.init(n); cd.add_edge(u,v); cd.build(); int p=cd.par[v]; struct cen_decomp { int n; vector> adj, chd; @@ -18,7 +18,7 @@ struct cen_decomp { siz.assign(n + 1, 0); used.assign(n + 1, 0); } - void add(int u, int v) { + void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } diff --git a/src/3-tree/tree_hld.cpp b/src/3-tree/tree_hld.cpp index fcd8f9a..52e63e1 100644 --- a/src/3-tree/tree_hld.cpp +++ b/src/3-tree/tree_hld.cpp @@ -3,7 +3,7 @@ // what: heavy-light decomposition for path sum on tree (node values). // time: build O(n), update/query O(log^2 n); memory: O(n) // constraint: 1-indexed tree. -// usage: hld_tree h; h.init(n); h.add(u,v); h.build(1); h.set(v,x); ll s=h.qry(u,v); +// usage: hld_tree h; h.init(n); h.add_edge(u,v); h.build(1); h.set(v,x); ll s=h.query(u,v); struct hld_tree { seg_tree seg; @@ -22,7 +22,7 @@ struct hld_tree { top.assign(n + 1, 0); in.assign(n + 1, 0); } - void add(int u, int v) { + void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } @@ -55,7 +55,7 @@ struct hld_tree { seg.build(a); } void set(int v, ll val) { seg.set(in[v], val); } - ll qry(int a, int b) const { + ll query(int a, int b) const { ll ret = 0; while (top[a] != top[b]) { if (dep[top[a]] < dep[top[b]]) swap(a, b); diff --git a/src/3-tree/tree_vtree.cpp b/src/3-tree/tree_vtree.cpp index 4affd1f..04b2a69 100644 --- a/src/3-tree/tree_vtree.cpp +++ b/src/3-tree/tree_vtree.cpp @@ -3,7 +3,7 @@ // what: virtual tree builder for subset DP using LCA and dfs order. // time: build O(n log n), make O(k log k); memory: O(n log n) // constraint: 1-indexed tree. -// usage: tree_comp tc; tc.init(n); tc.add(u,v); tc.build(root); auto nodes=tc.make(vs); // use tc.vt_adj +// usage: tree_comp tc; tc.init(n); tc.add_edge(u,v); tc.build(root); auto nodes=tc.make(vs); // use tc.vt_adj struct tree_comp { int n, lg, tim; vector> adj, up, vt_adj; @@ -21,7 +21,7 @@ struct tree_comp { dep.assign(n + 1, 0); tim = 0; } - void add(int u, int v) { + void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } diff --git a/src/3-tree/tree_xchg.cpp b/src/3-tree/tree_xchg.cpp index 6e9ecf8..b660b56 100644 --- a/src/3-tree/tree_xchg.cpp +++ b/src/3-tree/tree_xchg.cpp @@ -3,7 +3,7 @@ // what: maximize sum w[i]*completion_time[i] under precedence "parent before child" on rooted tree. // time: O(n log n); memory: O(n) // constraint: 1-indexed tree; cw[i]=w[i]*t[i]. -// usage: tree_xchg tx; tx.init(n, root); tx.add(u,v); // set tx.ds.w/t/cw; ll ans=tx.run(); +// usage: tree_xchg tx; tx.init(n, root); tx.add_edge(u,v); // set tx.ds.w/t/cw; ll ans=tx.run(); struct tree_xchg { struct uf { vector par; @@ -42,7 +42,7 @@ struct tree_xchg { par.assign(n + 1, 0); ds.init(n); } - void add(int u, int v) { + void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } diff --git a/tests/1-ds/test_ds_segtree.cpp b/tests/1-ds/test_ds_segtree.cpp index 1b05397..ebf5d81 100644 --- a/tests/1-ds/test_ds_segtree.cpp +++ b/tests/1-ds/test_ds_segtree.cpp @@ -248,7 +248,7 @@ void test_seg2dc_basic() { for (auto &op : ops) { if (op.type == 0) st.mark_set(op.x1, op.y1); - else st.mark_qry(op.x1, op.x2, op.y1, op.y2); + else st.mark_query(op.x1, op.x2, op.y1, op.y2); } st.prep(); @@ -294,7 +294,7 @@ void test_seg2dc_random() { for (auto &op : ops) { if (op.type == 0) st.mark_set(op.x1, op.y1); - else st.mark_qry(op.x1, op.x2, op.y1, op.y2); + else st.mark_query(op.x1, op.x2, op.y1, op.y2); } st.prep(); diff --git a/tests/2-graph/test_cc_bcc.cpp b/tests/2-graph/test_cc_bcc.cpp index 41a3fae..838b66b 100644 --- a/tests/2-graph/test_cc_bcc.cpp +++ b/tests/2-graph/test_cc_bcc.cpp @@ -109,7 +109,7 @@ void t_fix() { vector ed = {{1, 2}, {2, 3}}; bcc_graph g; g.init(n); - for (auto [u, v] : ed) g.add(u, v); + for (auto [u, v] : ed) g.add_edge(u, v); g.run(); auto ap = g.ap; auto ae = g.ae; @@ -135,7 +135,7 @@ void t_rnd() { } bcc_graph g; g.init(n); - for (auto [u, v] : ed) g.add(u, v); + for (auto [u, v] : ed) g.add_edge(u, v); g.run(); auto ap = g.ap; auto ae = g.ae; diff --git a/tests/2-graph/test_cc_scc.cpp b/tests/2-graph/test_cc_scc.cpp index 278eea1..8c8960e 100644 --- a/tests/2-graph/test_cc_scc.cpp +++ b/tests/2-graph/test_cc_scc.cpp @@ -55,13 +55,13 @@ void t_scc() { scc_kosa s1; s1.init(n); for (int u = 1; u <= n; u++) - for (int v : g[u]) s1.add(u, v); + for (int v : g[u]) s1.add_edge(u, v); s1.run(); scc_tarjan s2; s2.init(n); for (int u = 1; u <= n; u++) - for (int v : g[u]) s2.add(u, v); + for (int v : g[u]) s2.add_edge(u, v); s2.run(); for (int i = 1; i <= n; i++) diff --git a/tests/2-graph/test_euler_circ.cpp b/tests/2-graph/test_euler_circ.cpp index c030326..451255a 100644 --- a/tests/2-graph/test_euler_circ.cpp +++ b/tests/2-graph/test_euler_circ.cpp @@ -54,7 +54,7 @@ bool can_na(int n, const vector> &cnt) { } void add_ed(euler_cir &g, vector> &cnt, int u, int v) { - g.add(u, v); + g.add_edge(u, v); if (u == v) cnt[u][u]++; else cnt[u][v]++, cnt[v][u]++; } diff --git a/tests/2-graph/test_sp_basic.cpp b/tests/2-graph/test_sp_basic.cpp index 12b8070..65f2347 100644 --- a/tests/2-graph/test_sp_basic.cpp +++ b/tests/2-graph/test_sp_basic.cpp @@ -37,7 +37,7 @@ void t_dijk() { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(0, 9); ed.push_back({u, v, w}); - dj.add(u, v, w); + dj.add_edge(u, v, w); } auto d = floy(n, ed); int s = rnd(1, n); @@ -63,7 +63,7 @@ void t_bell() { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(-5, 9); ed.push_back({u, v, w}); - bl.add(u, v, w); + bl.add_edge(u, v, w); } auto d = floy(n, ed); int s = rnd(1, n); @@ -98,7 +98,7 @@ void t_floy() { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(-5, 9); ed.push_back({u, v, w}); - fl.add(u, v, w); + fl.add_edge(u, v, w); } auto d = floy(n, ed); bool neg = 0; diff --git a/tests/2-graph/test_sp_kth.cpp b/tests/2-graph/test_sp_kth.cpp index 1b7d0ca..6e93654 100644 --- a/tests/2-graph/test_sp_kth.cpp +++ b/tests/2-graph/test_sp_kth.cpp @@ -36,8 +36,8 @@ void t_fix() { g[1].push_back({1, 2}); g[2].push_back({1, 3}); ks.init(n); - ks.add(1, 2, 1); - ks.add(2, 3, 1); + ks.add_edge(1, 2, 1); + ks.add_edge(2, 3, 1); auto a = kth_na(n, g, 1, 3, 3); auto b = ks.run(1, 3, 3); assert(a == b); @@ -53,7 +53,7 @@ void t_rnd() { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(1, 5); g[u].push_back({w, v}); - ks.add(u, v, w); + ks.add_edge(u, v, w); } int s = rnd(1, n), e = rnd(1, n), k = rnd(1, 10); auto a = kth_na(n, g, s, e, k); diff --git a/tests/3-tree/test_lca_sparse.cpp b/tests/3-tree/test_lca_sparse.cpp index 25a0d35..924d17e 100644 --- a/tests/3-tree/test_lca_sparse.cpp +++ b/tests/3-tree/test_lca_sparse.cpp @@ -44,7 +44,7 @@ void t_rnd() { } lca_sparse l; l.init(n); - for (int v = 2; v <= n; v++) l.add(v, par[v]); + for (int v = 2; v <= n; v++) l.add_edge(v, par[v]); l.build(1); for (int q = 0; q < 50; q++) { int a = rnd(1, n), b = rnd(1, n); diff --git a/tests/3-tree/test_tree_centroid.cpp b/tests/3-tree/test_tree_centroid.cpp index 4a4d2bf..7840e0d 100644 --- a/tests/3-tree/test_tree_centroid.cpp +++ b/tests/3-tree/test_tree_centroid.cpp @@ -59,7 +59,7 @@ void check_one(const vector> &adj) { cd.init(n); for (int u = 1; u <= n; u++) for (int v : adj[u]) - if (u < v) cd.add(u, v); + if (u < v) cd.add_edge(u, v); cd.build(1); int root = get_root(n, cd.par); diff --git a/tests/3-tree/test_tree_hld.cpp b/tests/3-tree/test_tree_hld.cpp index 2f92e04..c09035d 100644 --- a/tests/3-tree/test_tree_hld.cpp +++ b/tests/3-tree/test_tree_hld.cpp @@ -51,14 +51,14 @@ void t_fix() { h.init(n); for (int u = 1; u <= n; u++) for (int v : adj[u]) - if (u < v) h.add(u, v); + if (u < v) h.add_edge(u, v); h.build(1); vector val = {0, 1, 2, 3, 4}; for (int i = 1; i <= n; i++) h.set(i, val[i]); auto p = path_nodes(n, adj, 3, 4); ll sum = 0; for (int v : p) sum += val[v]; - assert(h.qry(3, 4) == sum); + assert(h.query(3, 4) == sum); } void t_rnd() { @@ -73,7 +73,7 @@ void t_rnd() { } hld_tree h; h.init(n); - for (int v = 2; v <= n; v++) h.add(v, par[v]); + for (int v = 2; v <= n; v++) h.add_edge(v, par[v]); h.build(1); vector val(n + 1); for (int i = 1; i <= n; i++) { @@ -85,7 +85,7 @@ void t_rnd() { auto p = path_nodes(n, adj, a, b); ll sum = 0; for (int v : p) sum += val[v]; - assert(h.qry(a, b) == sum); + assert(h.query(a, b) == sum); } } } diff --git a/tests/3-tree/test_tree_vtree.cpp b/tests/3-tree/test_tree_vtree.cpp index 44432d3..7266ea1 100644 --- a/tests/3-tree/test_tree_vtree.cpp +++ b/tests/3-tree/test_tree_vtree.cpp @@ -85,7 +85,7 @@ void check_one(const vector> &adj, const vector &vs) { tc.init(n); for (int u = 1; u <= n; u++) for (int v : adj[u]) - if (u < v) tc.add(u, v); + if (u < v) tc.add_edge(u, v); tc.build(1); if (vs.empty()) { diff --git a/tests/3-tree/test_tree_xchg.cpp b/tests/3-tree/test_tree_xchg.cpp index c325629..cf5ffde 100644 --- a/tests/3-tree/test_tree_xchg.cpp +++ b/tests/3-tree/test_tree_xchg.cpp @@ -89,7 +89,7 @@ void check_one(const vector> &adj, int root, const vector &w, co tx.init(n, root); for (int u = 1; u <= n; u++) for (int v : adj[u]) - if (u < v) tx.add(u, v); + if (u < v) tx.add_edge(u, v); for (int i = 1; i <= n; i++) { tx.ds.w[i] = w[i]; tx.ds.t[i] = t[i];