# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
283531 | ijxjdjd | Network (BOI15_net) | Java | 2222 ms | 133476 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class net {
static ArrayList<Integer>[] adj;
public static void main(String[] args) {
try {
Reader r = new Reader();
int N = r.nextInt();
adj = new ArrayList[N];
for (int i = 0; i < N; i++) {
adj[i] = new ArrayList<>();
}
for (int i = 0; i < N - 1; i++) {
int a = r.nextInt() - 1;
int b = r.nextInt() - 1;
adj[a].add(b);
adj[b].add(a);
}
PrintWriter out = new PrintWriter(System.out);
if (N == 2) {
out.println("1\n1 2");
} else {
for (int i = 0; i < N; i++) {
if (adj[i].size() > 1) {
Set f = dfs(i);
if (f.a2 == -1) {
ans.add(new Set(f.a1, i));
} else {
ans.add(new Set(f.a1, f.a2));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |