답안 #165770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165770 2019-11-28T14:42:14 Z _qVp_ Burza (COCI16_burza) C++14
160 / 160
105 ms 3272 KB
#include <bits/stdc++.h>
    
using namespace std;
    
const int md = 410;
    
int n, k, r = 1;
vector <int> adj[md], v[md];
int start[md], finish[md], depth[md];
bool f[md][(1 << 20) + 5];
    
void dfs(int u, int par) {
    if (depth[u] == k - 1) {
        start[u] = r++;
        finish[u] = r;
        return ;
    }
    start[u] = r;
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (v == par) continue;
        depth[v] = depth[u] + 1;
        dfs(v, u);
    }
    finish[u] = r;
}
    
int getbit(int x, int i) {
    return ((x >> i) & 1);
}
    
int onbit(int x, int i) {
    return (x | (1 << i));
}
    
bool check() {
    f[1][0] = 1;
    //cout << r << endl;
    for(int i = 2; i <= n; i++) {
        v[start[i]].push_back(i);
        //cout << i << " " << start[i] << " " << finish[i] << " " << depth[i] << endl;
    }
    //return 0;
    for(int i = 1; i <= r; i++) 
        for(int mask = 0; mask < (1 << k); mask++) {
            if (!f[i][mask]) continue;
            for(int t = 0; t < v[i].size(); t++) {
                int x = v[i][t];
                if (!getbit(mask, depth[x]))
                    f[finish[x]][onbit(mask, depth[x])] = 1;
            }
        }
    //return 0;
    for(int mask = 0; mask < (1 << k); mask++)
        if (f[r][mask])
            return true;
    return false;
}
    
int main() {
    //freopen("test.in", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    if (k * k >= n) {
        cout << "DA";
        return 0;
    }
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    depth[1] = -1;
    dfs(1, 0);
    //return 0;
    cout << (check() ? "DA" : "NE");
    return 0;
}

Compilation message

burza.cpp: In function 'void dfs(int, int)':
burza.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~
burza.cpp: In function 'bool check()':
burza.cpp:47:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int t = 0; t < v[i].size(); t++) {
                            ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1016 KB Output is correct
2 Correct 51 ms 2680 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 2816 KB Output is correct
2 Correct 51 ms 2688 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 76 ms 2976 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 2936 KB Output is correct
2 Correct 57 ms 2684 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1372 KB Output is correct
2 Correct 71 ms 3272 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 2352 KB Output is correct
2 Correct 61 ms 3064 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2748 KB Output is correct
2 Correct 63 ms 2788 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 3028 KB Output is correct
2 Correct 65 ms 2808 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 76 ms 3192 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1272 KB Output is correct
2 Correct 62 ms 2836 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 78 ms 2936 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1656 KB Output is correct
2 Correct 73 ms 2992 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 29 ms 1656 KB Output is correct
6 Correct 3 ms 632 KB Output is correct