Submission #1340172

#TimeUsernameProblemLanguageResultExecution timeMemory
1340172tieptrinhBurza (COCI16_burza)Java
Compilation error
0 ms0 KiB
import java.io.*;
import java.util.*;

public class Main {

    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);
        }

        boolean canFinish = solve();

        if (canFinish) {
            System.out.println("DA");
        } else {
            System.out.println("NE");
        }
    }

    static boolean solve() {
        boolean[] visited = new boolean[N + 1];
        return dfs(1, 0, visited) <= K;
    }
    
    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;
    }

    // ================= FAST SCANNER =================
    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)

burza.java:4: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
Note: burza.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

=======