Datasets:
ArXiv:
License:
Download data/train/ToreAad/Inf102/src/java/exercises/UnionFindExercise.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 951 Bytes
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/main/data/train/ToreAad/Inf102/src/java/exercises/UnionFindExercise.java
- Command line
-
hf download hf://datasets/RepoFusion/Stack-Repo/data/train/ToreAad/Inf102/src/java/exercises/UnionFindExercise.java
-
curl -L -o UnionFindExercise.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/main/data/train/ToreAad/Inf102/src/java/exercises/UnionFindExercise.java
951 Bytes
| package torea; | |
| import java.lang.StringBuilder; | |
| public class UnionFindExercise{ | |
| public static void main(String[] args){ | |
| Kattio io = new Kattio(System.in, System.out); | |
| int N = io.getInt(); | |
| int Q = io.getInt(); | |
| UnionFind.QuickUnion qf = new UnionFind.QuickUnion(N); | |
| StringBuilder sb = new StringBuilder(); | |
| for(int i = 0; i< Q; i++){ | |
| String command = io.getWord(); | |
| if (command.equals("?")){ | |
| int a = io.getInt(); | |
| int b = io.getInt(); | |
| if (qf.connected(a, b)) sb.append("yes").append("\n"); | |
| else sb.append("no").append("\n"); | |
| } | |
| else { | |
| int a = io.getInt(); | |
| int b = io.getInt(); | |
| qf.union(a, b); | |
| } | |
| } | |
| io.print(sb); | |
| io.flush(); | |
| io.close(); | |
| } | |
| } |