답안 #1013892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013892 2024-07-04T07:44:11 Z MMihalev Burza (COCI16_burza) C++14
160 / 160
38 ms 996 KB
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<map>
#include<random>
#include<chrono>
using namespace std;
const int MAX_N=4e2+2;
const int MASK=19;
int dp[(1<<MASK)];
int depth[MAX_N];
int in[MAX_N];
int out[MAX_N];
int T;
vector<int>nodes[MAX_N];
vector<int>g[MAX_N];
int n;
int k;
void dfs(int u,int par)
{
    if(depth[u]==k)
    {
        in[u]=++T;
        out[u]=T;
        return;
    }
    in[u]=1e9;
    for(int v:g[u])
    {
        if(v==par)continue;

        depth[v]=depth[u]+1;
        nodes[depth[v]].push_back(v);
        dfs(v,u);

        in[u]=min(in[u],in[v]);
        out[u]=max(out[u],out[v]);
    }
}
signed main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    if(k*k>=n)
    {
        cout<<"DA\n";
        return 0;
    }

    dfs(1,0);

    for(int mask=1;mask<(1<<k);mask++)
    {
        for(int ndepth=1;ndepth<=k;ndepth++)
        {
            if(((1<<(ndepth-1))&(mask))!=0)
            {
                for(int u:nodes[ndepth])
                {
                    if(in[u]<=dp[mask & (~(1<<(ndepth-1)))]+1)
                    {
                        dp[mask]=max(dp[mask],out[u]);
                    }
                }
            }
        }
        if(dp[mask]==T)
        {
            cout<<"DA\n";
            return 0;
        }
    }

    cout<<"NE\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 28 ms 868 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 860 KB Output is correct
2 Correct 27 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 28 ms 824 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 848 KB Output is correct
2 Correct 27 ms 956 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 29 ms 996 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 860 KB Output is correct
2 Correct 35 ms 872 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 856 KB Output is correct
2 Correct 27 ms 908 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 484 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 860 KB Output is correct
2 Correct 33 ms 884 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 33 ms 788 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 528 KB Output is correct
2 Correct 28 ms 916 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 480 KB Output is correct
2 Correct 38 ms 768 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 600 KB Output is correct
2 Correct 33 ms 792 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 21 ms 732 KB Output is correct
6 Correct 0 ms 344 KB Output is correct