Skip to content

Commit 18ca58a

Browse files
committed
Update index.ts
1 parent 226b929 commit 18ca58a

File tree

1 file changed

+31
-31
lines changed
  • checking-existence-of-edge-length-limited-paths-ii

1 file changed

+31
-31
lines changed
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
import { lowerBound } from "./lowerBound.ts";
22

33
export default class DistanceLimitedPathsExist {
4-
snaps: [number, number][][];
5-
father: number[];
6-
rank: number[];
7-
changed: Set<number>;
4+
#snaps: [number, number][][];
5+
#father: number[];
6+
#rank: number[];
7+
#changed: Set<number>;
88
constructor(n: number, edgeList: number[][]) {
9-
this.snaps = Array(n)
9+
this.#snaps = Array(n)
1010
.fill(0)
1111
.map((_, i) => [[0, i]]);
12-
this.father = [...Array(n).keys()];
13-
this.rank = Array(n).fill(0);
14-
this.changed = new Set();
12+
this.#father = [...Array(n).keys()];
13+
this.#rank = Array(n).fill(0);
14+
this.#changed = new Set();
1515
edgeList.sort((a, b) => a[2] - b[2]);
1616
let curLen = 0;
1717
for (const e of edgeList) {
1818
if (e[2] > curLen) {
19-
for (const node of this.changed) {
20-
this.snaps[node].push([curLen, this.father[node]]);
19+
for (const node of this.#changed) {
20+
this.#snaps[node].push([curLen, this.#father[node]]);
2121
}
22-
this.changed.clear();
22+
this.#changed.clear();
2323
curLen = e[2];
2424
}
25-
this.union(e[0], e[1]);
25+
this.#union(e[0], e[1]);
2626
}
2727
}
28-
union(a: number, b: number) {
29-
let fa = this.findFather(a);
30-
let fb = this.findFather(b);
28+
#union(a: number, b: number) {
29+
let fa = this.#findFather(a);
30+
let fb = this.#findFather(b);
3131

3232
if (fa != fb) {
33-
if (this.rank[fa] >= this.rank[fb]) {
33+
if (this.#rank[fa] >= this.#rank[fb]) {
3434
[fa, fb] = [fb, fa];
3535
}
36-
this.father[fa] = fb;
37-
this.rank[fb] = Math.max(this.rank[fb], this.rank[fa] + 1);
38-
this.changed.add(fa);
36+
this.#father[fa] = fb;
37+
this.#rank[fb] = Math.max(this.#rank[fb], this.#rank[fa] + 1);
38+
this.#changed.add(fa);
3939
}
4040
}
4141
query(p: number, q: number, limit: number): boolean {
42-
return this.findSnapRoot(p, limit) === this.findSnapRoot(q, limit);
42+
return this.#findSnapRoot(p, limit) === this.#findSnapRoot(q, limit);
4343
}
44-
findSnapRoot(node: number, limit: number): number {
44+
#findSnapRoot(node: number, limit: number): number {
4545
const index =
4646
lowerBound(
4747
0,
48-
this.snaps[node].length,
49-
(i: number) => this.snaps[node][i][0] - limit
48+
this.#snaps[node].length,
49+
(i: number) => this.#snaps[node][i][0] - limit
5050
) - 1;
51-
const f = this.snaps[node][index][1];
51+
const f = this.#snaps[node][index][1];
5252

5353
if (f == node) return f;
54-
else return this.findSnapRoot(f, limit);
54+
else return this.#findSnapRoot(f, limit);
5555
}
56-
findFather(b: number) {
56+
#findFather(b: number) {
5757
let a = b;
58-
while (this.father[a] !== a) {
59-
a = this.father[a];
58+
while (this.#father[a] !== a) {
59+
a = this.#father[a];
6060
}
61-
if (this.father[b] != a) {
62-
this.changed.add(b);
61+
if (this.#father[b] != a) {
62+
this.#changed.add(b);
6363
}
64-
this.father[b] = a;
64+
this.#father[b] = a;
6565
return a;
6666
}
6767
}

0 commit comments

Comments
 (0)