| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1340178 | tieptrinh | Burza (COCI16_burza) | Java | 55 ms | 19080 KiB |
import java.io.*;
import java.util.*;
public class burza {
static int N, K;
static List<Integer>[] adj;
public static void main(String[] args) throws Exception {
FastScanner fs = new FastScanner(System.in);
N = fs.nextInt();
K = fs.nextInt();
adj = new ArrayList[N + 1];
for (int i = 1; i <= N; i++) {
adj[i] = new ArrayList<>();
}
for (int i = 0; i < N - 1; i++) {
int u = fs.nextInt();
int v = fs.nextInt();
adj[u].add(v);
adj[v].add(u);
}
int maxDepth = dfs(1, 0, new boolean[N + 1]);
if (maxDepth < K) {
System.out.println("DA");
} else {
System.out.println("NE");
}
}
static int dfs(int u, int depth, boolean[] visited) {
visited[u] = true;
int maxDepth = depth;
for (int v : adj[u]) {
if (!visited[v]) {
maxDepth = Math.max(maxDepth, dfs(v, depth + 1, visited));
}
}
return maxDepth;
}
static class FastScanner {
private final InputStream in;
private final byte[] buffer = new byte[1 << 16];
private int ptr = 0, len = 0;
FastScanner(InputStream is) {
in = is;
}
private int read() throws IOException {
if (ptr >= len) {
len = in.read(buffer);
ptr = 0;
if (len <= 0) return -1;
}
return buffer[ptr++];
}
int nextInt() throws IOException {
int c, sign = 1, val = 0;
do {
c = read();
} while (c <= ' ');
if (c == '-') {
sign = -1;
c = read();
}
while (c > ' ') {
val = val * 10 + (c - '0');
c = read();
}
return val * sign;
}
}
}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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
