Commit aa02866 1 parent cf42f70 commit aa02866 Copy full SHA for aa02866
File tree 1 file changed +15
-5
lines changed
1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,7 @@ int main() {
242
242
</CPPSection>
243
243
244
244
<JavaSection>
245
+
245
246
import java.util.*;
246
247
247
248
class Node {
@@ -274,7 +275,9 @@ class LCT {
274
275
275
276
LCT(int n) {
276
277
nodes = new Node[n + 1];
277
- for (int i = 1; i <= n; i++) nodes[i] = new Node(i);
278
+ for (int i = 1; i <= n; i++) {
279
+ nodes[i] = new Node(i);
280
+ }
278
281
}
279
282
280
283
void rotate(Node child) {
@@ -307,7 +310,9 @@ class LCT {
307
310
while (!node.isRoot()) {
308
311
Node parent = node.parent;
309
312
Node grandparent = parent.parent;
310
- if (!parent.isRoot()) rotate((grandparent.right == parent) == (parent.right == node) ? parent : node);
313
+ if (!parent.isRoot()) {
314
+ rotate((grandparent.right == parent) == (parent.right == node) ? parent : node);
315
+ }
311
316
rotate(node);
312
317
}
313
318
node.push();
@@ -367,15 +372,20 @@ public class Main {
367
372
int u = sc.nextInt();
368
373
int v = sc.nextInt();
369
374
370
- if (command.equals("add")) lc.link(u, v);
371
- else if (command.equals("rem")) lc.cut(u, v);
372
- else if (command.equals("conn")) System.out.println(lc.connected(u, v) ? "YES" : "NO");
375
+ if (command.equals("add")) {
376
+ lc.link(u, v);
377
+ } else if (command.equals("rem")) {
378
+ lc.cut(u, v);
379
+ } else if (command.equals("conn")) {
380
+ System.out.println(lc.connected(u, v) ? "YES" : "NO");
381
+ }
373
382
}
374
383
375
384
sc.close();
376
385
}
377
386
}
378
387
388
+
379
389
</JavaSection>
380
390
</LanguageSection>
381
391
You can’t perform that action at this time.
0 commit comments