답안 #1117448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117448 2024-11-23T16:09:53 Z kfhjad Burza (COCI16_burza) C++17
48 / 160
366 ms 18524 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int N, K;
int best[401][401]; // cant mark node till xth turn
int dp[1 << 21];
vector<int> adj[401];
int depth[401];

void dfs(int node, int p, int d)
{
    vector<int> paths;
    
    for (int i : adj[node])
    {
        if (i == p)
            continue;
        
        dfs(i, node, d + 1);
        
        depth[node] = max(depth[node], depth[i]);
        
        if (depth[i] >= K)
            paths.push_back(i);
    }
    
    int n = paths.size();
    
    for (int move = 1; move <= K; ++move) // start marking till move'th move
    {
        if (move <= d)
            best[node][move] = 1;
        else if (n > K)
            best[node][move] = 1e9;
        else
        {
            for (int mask = 1; mask < (1 << n); ++mask)
            {
                dp[mask] = 1e9;
                
                for (int i = 0; i < n; ++i)
                    if (mask & (1 << i))
                    {
                        int cur_move = move + dp[mask ^ (1 << i)];
                        
                        if (cur_move > K) // not possible
                            continue;
                            
                        dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + best[paths[i]][cur_move]);
                    }
            }
            
            best[node][move] = dp[(1 << n) - 1];
        }
    }
    
    for (int& i : best[node])
        if (i == 0)
            i = 1e9;
    
    depth[node] = max(depth[node], d);
}

int main()
{
    cin.tie(NULL) -> sync_with_stdio(false);
    cin >> N >> K;
    
    for (int i = 1; i < N; ++i)
    {
        int a, b;
        cin >> a >> b;
        
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    dfs(1, 0, 0);
    
    if (K * K >= N)
        cout << "DA" << endl;
    else
        cout << (best[1][1] <= K ? "DA" : "NE") << endl;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2896 KB Output is correct
2 Correct 143 ms 5200 KB Output is correct
3 Correct 366 ms 9288 KB Output is correct
4 Runtime error 178 ms 18504 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 4944 KB Output is correct
2 Correct 148 ms 5200 KB Output is correct
3 Correct 24 ms 5200 KB Output is correct
4 Correct 73 ms 7248 KB Output is correct
5 Correct 133 ms 5200 KB Output is correct
6 Correct 2 ms 2896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 4944 KB Output is correct
2 Correct 135 ms 4944 KB Output is correct
3 Correct 73 ms 5148 KB Output is correct
4 Correct 178 ms 9288 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2896 KB Output is correct
2 Correct 140 ms 5204 KB Output is correct
3 Correct 32 ms 5200 KB Output is correct
4 Runtime error 194 ms 18504 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 4944 KB Output is correct
2 Correct 141 ms 4944 KB Output is correct
3 Runtime error 197 ms 18524 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 4944 KB Output is correct
2 Correct 134 ms 5172 KB Output is correct
3 Correct 11 ms 5200 KB Output is correct
4 Runtime error 176 ms 18504 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 5200 KB Output is correct
2 Correct 143 ms 5180 KB Output is correct
3 Runtime error 206 ms 18424 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2896 KB Output is correct
2 Correct 163 ms 5200 KB Output is correct
3 Correct 38 ms 5200 KB Output is correct
4 Runtime error 230 ms 18504 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2640 KB Output is correct
2 Correct 128 ms 5136 KB Output is correct
3 Correct 28 ms 5140 KB Output is correct
4 Runtime error 197 ms 18500 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 5096 KB Output is correct
2 Correct 126 ms 5200 KB Output is correct
3 Correct 36 ms 5200 KB Output is correct
4 Correct 26 ms 5048 KB Output is correct
5 Correct 61 ms 5108 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct