답안 #825586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825586 2023-08-15T05:09:19 Z powervic08 Burza (COCI16_burza) Java 11
0 / 160
72 ms 8800 KB
import java.util.*;
import java.io.*;

public class burza {

    static int[] dp;
    static ArrayList<ArrayList<Integer>> arr;

    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        dp = new int[n];
        arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arr.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            st = new StringTokenizer(f.readLine());
            int x = Integer.parseInt(st.nextToken()) - 1;
            int y = Integer.parseInt(st.nextToken()) - 1;
            arr.get(x).add(y);
            arr.get(y).add(x);
        }
        out.println(fillDp(0, new boolean[n]) < k ? "DA" : "NE");
        out.close();
        f.close();
    }

    public static int fillDp(int i, boolean[] visited) {
        visited[i] = true;
        if (dp[i] != 0) return dp[i];
        if (arr.get(i).size() == 0) return 0;
        else if (arr.get(i).size() == 1 && i != 0) return 0;
        ArrayList<Integer> pos = new ArrayList<>();
        for (int x : arr.get(i)) {
            if (!visited[x])
                pos.add(fillDp(x, visited) + 1);
        }
        Collections.sort(pos);
        if (pos.size() == 1) return 0;
        return dp[i] = pos.get(pos.size() - 2);
    }

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 8800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 8584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 8412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 8328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 8592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 8628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 8476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 8416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 8328 KB Output isn't correct
2 Halted 0 ms 0 KB -