@@ -24,17 +24,17 @@ public static class TreeNode {
24
24
// Number of nodes in the subtree. Computed when tree is built.
25
25
private int n ;
26
26
27
- private int id ;
27
+ private int index ;
28
28
private TreeNode parent ;
29
29
private List <TreeNode > children ;
30
30
31
31
// Useful constructor for root node.
32
- public TreeNode (int id ) {
33
- this (id , /*parent=*/ null );
32
+ public TreeNode (int index ) {
33
+ this (index , /*parent=*/ null );
34
34
}
35
35
36
- public TreeNode (int id , TreeNode parent ) {
37
- this .id = id ;
36
+ public TreeNode (int index , TreeNode parent ) {
37
+ this .index = index ;
38
38
this .parent = parent ;
39
39
children = new LinkedList <>();
40
40
}
@@ -54,8 +54,8 @@ public int size() {
54
54
return n ;
55
55
}
56
56
57
- public int id () {
58
- return id ;
57
+ public int index () {
58
+ return index ;
59
59
}
60
60
61
61
public TreeNode parent () {
@@ -79,9 +79,9 @@ public static TreeNode rootTree(List<List<Integer>> graph, int rootId) {
79
79
// Do dfs to construct rooted tree.
80
80
private static TreeNode buildTree (List <List <Integer >> graph , TreeNode node ) {
81
81
int subtreeNodeCount = 1 ;
82
- for (int neighbor : graph .get (node .id ())) {
82
+ for (int neighbor : graph .get (node .index ())) {
83
83
// Ignore adding an edge pointing back to parent.
84
- if (node .parent () != null && neighbor == node .parent ().id ()) {
84
+ if (node .parent () != null && neighbor == node .parent ().index ()) {
85
85
continue ;
86
86
}
87
87
@@ -97,14 +97,14 @@ private static TreeNode buildTree(List<List<Integer>> graph, TreeNode node) {
97
97
98
98
@ Override
99
99
public String toString () {
100
- return String .valueOf (id );
100
+ return String .valueOf (index );
101
101
}
102
102
}
103
103
104
104
private final int n ;
105
105
private final TreeNode root ;
106
106
107
- private int index = 0 ;
107
+ private int tourIndex = 0 ;
108
108
private boolean preprocessed ;
109
109
110
110
// Populated when constructing Euler Tour.
@@ -139,10 +139,10 @@ private void preprocess() {
139
139
}
140
140
141
141
private void visit (TreeNode node , long depth ) {
142
- nodeOrder [index ] = node ;
143
- nodeDepth [index ] = depth ;
144
- last [node .id ()] = index ;
145
- index ++;
142
+ nodeOrder [tourIndex ] = node ;
143
+ nodeDepth [tourIndex ] = depth ;
144
+ last [node .index ()] = tourIndex ;
145
+ tourIndex ++;
146
146
}
147
147
148
148
// Construct Euler Tour by populating the 'depth' and 'nodeOrder' arrays.
@@ -323,19 +323,19 @@ private static void example1() {
323
323
324
324
TreeNode lca = solver .lca (10 , 15 );
325
325
System .out .printf ("LCA of 10 and 15 = %s\n " , lca );
326
- if (lca .id () != 5 ) {
326
+ if (lca .index () != 5 ) {
327
327
System .out .println ("Error, expected lca to be 5" );
328
328
}
329
329
330
330
lca = solver .lca (13 , 14 );
331
331
System .out .printf ("LCA of 13 and 14 = %s\n " , lca );
332
- if (lca .id () != 2 ) {
332
+ if (lca .index () != 2 ) {
333
333
System .out .println ("Error, expected lca to be 2" );
334
334
}
335
335
336
336
lca = solver .lca (9 , 11 );
337
337
System .out .printf ("LCA of 9 and 11 = %s\n " , lca );
338
- if (lca .id () != 0 ) {
338
+ if (lca .index () != 0 ) {
339
339
System .out .println ("Error, expected lca to be 0" );
340
340
}
341
341
}
0 commit comments