# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011106 |
2024-06-29T20:07:19 Z |
Oz121 |
Burza (COCI16_burza) |
Java 11 |
|
732 ms |
27384 KB |
import java.io.*;
import java.util.*;
public class burza {
public static int num; public static int k; public static HashMap<Integer, ArrayList<Integer>> tree;
public static int[] depth; public static int[][] interval; //Interval of leaves covered by a node
public static int count; public static HashMap<Integer, Integer> idx;
public static void main(String[] args) throws IOException {
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer l1 = new StringTokenizer(scan.readLine());
num = Integer.parseInt(l1.nextToken()); k = Integer.parseInt(l1.nextToken()); tree = new HashMap<>();
for (int i = 0;i<num;i++) tree.put(i,new ArrayList<>());
for (int i = 0;i<num-1;i++) {
StringTokenizer st = new StringTokenizer(scan.readLine());
int a = Integer.parseInt(st.nextToken())-1; int b = Integer.parseInt(st.nextToken())-1;
tree.get(a).add(b); tree.get(b).add(a);
}
if (k*k>=num) System.out.println("DA");
else System.out.println(solve());
}
public static String solve () {
idx = new HashMap<>(); count = 0;
depth = new int[num];
Arrays.fill(depth, -1); depth[0] = 0;
dfs1(0);
interval = new int[num][2];
for (int i = 0;i<num;i++) {
interval[i][0] = Integer.MAX_VALUE; interval[i][1] = Integer.MIN_VALUE;
}
count = 0;
for (int i = 0;i<num;i++) {
if (depth[i]==k) {
interval[i][0] = idx.get(i); interval[i][1] = idx.get(i);
dfs2(i,i); count++;
}
}
//System.out.println(idx);
/*for (int i = 0;i<num;i++) {
System.out.println(interval[i][0]+" "+interval[i][1]);
}*/
int[] dp = new int[1<<k];
Arrays.fill(dp, -1); dp[0] = 0;
for (int i = 1;i<1<<k;i++) {
for (int j = 0;j<k;j++) {
if ((i&(1<<j))==0) continue;
int prev = i-(1<<j);
for (int l = 0;l<num;l++) {
if (depth[l]!=j+1) continue;
if (interval[l][0]<=dp[prev]+1) {
dp[i] = Math.max(dp[i], interval[l][1]);
}
}
}
}
for (int i = 0;i<(1<<k);i++) {
if (dp[i] == count - 1) return "DA";
}
return "NE";
}
public static void dfs1 (int curr) {
for (int next : tree.get(curr)) {
if (depth[next]==-1) {
depth[next] = depth[curr]+1;
if (depth[next]==k) {
idx.put(next, count); count++;
}
dfs1(next);
}
}
}
public static void dfs2 (int curr, int child) {
for (int next : tree.get(curr)) {
if (depth[next]<depth[curr]) { //Going up the tree
if (idx.get(child)<interval[next][0]) interval[next][0] = idx.get(child);
if (idx.get(child)>interval[next][1]) interval[next][1] = idx.get(child);
dfs2(next, child);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
23428 KB |
Output is correct |
2 |
Correct |
625 ms |
25448 KB |
Output is correct |
3 |
Correct |
57 ms |
24204 KB |
Output is correct |
4 |
Correct |
54 ms |
22664 KB |
Output is correct |
5 |
Correct |
71 ms |
23728 KB |
Output is correct |
6 |
Correct |
52 ms |
24292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
653 ms |
23812 KB |
Output is correct |
2 |
Correct |
594 ms |
27088 KB |
Output is correct |
3 |
Correct |
57 ms |
22372 KB |
Output is correct |
4 |
Correct |
56 ms |
22352 KB |
Output is correct |
5 |
Correct |
600 ms |
23408 KB |
Output is correct |
6 |
Correct |
67 ms |
23272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
25320 KB |
Output is correct |
2 |
Correct |
562 ms |
23472 KB |
Output is correct |
3 |
Correct |
74 ms |
24180 KB |
Output is correct |
4 |
Correct |
50 ms |
22396 KB |
Output is correct |
5 |
Correct |
70 ms |
26848 KB |
Output is correct |
6 |
Correct |
49 ms |
24216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
24952 KB |
Output is correct |
2 |
Incorrect |
732 ms |
24896 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
662 ms |
23340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
586 ms |
25300 KB |
Output is correct |
2 |
Correct |
622 ms |
22824 KB |
Output is correct |
3 |
Correct |
54 ms |
26256 KB |
Output is correct |
4 |
Correct |
54 ms |
26124 KB |
Output is correct |
5 |
Correct |
67 ms |
23196 KB |
Output is correct |
6 |
Correct |
74 ms |
23112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
644 ms |
23064 KB |
Output is correct |
2 |
Correct |
610 ms |
22820 KB |
Output is correct |
3 |
Correct |
53 ms |
22472 KB |
Output is correct |
4 |
Correct |
55 ms |
22092 KB |
Output is correct |
5 |
Correct |
594 ms |
23164 KB |
Output is correct |
6 |
Correct |
79 ms |
22976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
24816 KB |
Output is correct |
2 |
Correct |
633 ms |
22964 KB |
Output is correct |
3 |
Correct |
49 ms |
21908 KB |
Output is correct |
4 |
Correct |
57 ms |
22652 KB |
Output is correct |
5 |
Correct |
58 ms |
26952 KB |
Output is correct |
6 |
Correct |
68 ms |
23544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
22560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
278 ms |
27384 KB |
Output is correct |
2 |
Correct |
619 ms |
23408 KB |
Output is correct |
3 |
Correct |
61 ms |
22260 KB |
Output is correct |
4 |
Correct |
51 ms |
22352 KB |
Output is correct |
5 |
Correct |
289 ms |
23064 KB |
Output is correct |
6 |
Correct |
46 ms |
22292 KB |
Output is correct |