33// what: compute single-source shortest paths with non-negative edges (Dijkstra).
44// time: O((n+m)log n); memory: O(n+m)
55// constraint: directed; 1-indexed; w >= 0.
6- // usage: dijkstra g; g.init(n); g.add (u,v,w); auto dist=g.run(s);
6+ // usage: dijkstra g; g.init(n); g.add_edge (u,v,w); auto dist=g.run(s);
77struct dijkstra {
88 static const ll INF = (1LL << 62 );
99 int n;
@@ -14,7 +14,7 @@ struct dijkstra {
1414 n = n_;
1515 adj.assign (n + 1 , {});
1616 }
17- void add (int u, int v, ll w) { adj[u].push_back ({w, v}); }
17+ void add_edge (int u, int v, ll w) { adj[u].push_back ({w, v}); }
1818 vector<ll> run (int s) {
1919 // result: dist[i] = shortest distance from s to i.
2020 vector<ll> dist (n + 1 , INF);
@@ -39,7 +39,7 @@ struct dijkstra {
3939// what: compute single-source shortest paths with possible negative edges.
4040// time: O(nm); memory: O(n+m)
4141// constraint: directed; 1-indexed; detects negative cycle reachable from s.
42- // usage: bell_ford g; g.init(n); g.add (u,v,w); bool ok=g.run(s, dist);
42+ // usage: bell_ford g; g.init(n); g.add_edge (u,v,w); bool ok=g.run(s, dist);
4343struct bell_ford {
4444 static const ll INF = (1LL << 62 );
4545 int n;
@@ -50,7 +50,7 @@ struct bell_ford {
5050 n = n_;
5151 ed.clear ();
5252 }
53- void add (int u, int v, ll w) { ed.push_back ({u, v, w}); }
53+ void add_edge (int u, int v, ll w) { ed.push_back ({u, v, w}); }
5454 bool run (int s, vector<ll> &dist) {
5555 // result: false if a negative cycle is reachable.
5656 dist.assign (n + 1 , INF);
@@ -74,7 +74,7 @@ struct bell_ford {
7474// what: compute all-pairs shortest paths with dynamic programming.
7575// time: O(n^3); memory: O(n^2)
7676// constraint: directed; 1-indexed; watch overflow on INF.
77- // usage: floyd g; g.init(n); g.add (u,v,w); g.run(); auto &d=g.d;
77+ // usage: floyd g; g.init(n); g.add_edge (u,v,w); g.run(); auto &d=g.d;
7878struct floyd {
7979 static const ll INF = (1LL << 62 );
8080 int n;
@@ -86,7 +86,7 @@ struct floyd {
8686 d.assign (n + 1 , vector<ll>(n + 1 , INF));
8787 for (int i = 1 ; i <= n; i++) d[i][i] = 0 ;
8888 }
89- void add (int u, int v, ll w) { d[u][v] = min (d[u][v], w); }
89+ void add_edge (int u, int v, ll w) { d[u][v] = min (d[u][v], w); }
9090 void run () {
9191 // goal: relax all pairs via intermediate nodes.
9292 for (int k = 1 ; k <= n; k++) {
0 commit comments