답안 #1103908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103908 2024-10-22T07:58:06 Z dead0ne Burza (COCI16_burza) C++17
0 / 160
893 ms 524288 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<long long,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 1000000007
#define MX 405
using namespace std;

int n,k;
int cnt=0, tim=0;
vi edges[MX], ed1[MX], dep(MX), ind(MX), revind(MX), paro(MX);
vector<vector<int>> dp;
void dfs(int node, int par){
    for(auto i:ed1[node]){
        if(i==par) continue;
        dep[i]=dep[node]+1;
        dfs(i, node);
    }
    if(edges[node].size() || dep[node]==k){
        cnt++;
        if(par!=0){
            edges[node].pb(par);
            edges[par].pb(node);
        }
    }
}
void dfs2(int node, int par){
    paro[node]=par;
    ind[node]=++tim;
    revind[ind[node]]=node;
    for(auto i:edges[node]) if(i!=par) dfs2(i, node);
}

void solve(){
    cin >> n >> k;
    for(int i=1; i<n; i++){
        int a,b; cin >> a >> b;
        ed1[a].pb(b);
        ed1[b].pb(a);
    }
    dep[1]=0;
    dfs(1,0);
    n=cnt;
    if(k*k>=n){
        cout << "DA\n";
        return;
    }

    dfs2(1, 0);
    dp.resize(n+1, vector<int>(1<<k, 0));
    int lolol[n+1];
    lolol[1]=1;
    for(int i=2; i<=n; i++){
        if(ind[i]-1==ind[paro[i]]) lolol[i]=lolol[paro[i]];
        else lolol[i]=i;
    }
    for(int i=2; i<=n; i++){
        for(int j=0; j<1<<k; j++){
            dp[i][j]|=dp[ind[paro[revind[i]]]][j];
            if(j&(1<<(dep[revind[i]]-1))) dp[i][j]|=lolol[i]==1?1:dp[lolol[i]-1][j^(1<<(dep[revind[i]]-1))];
        }
    }
    if(dp[n][(1<<k)-1]) cout << "DA\n";
    else cout << "NE\n";
}

 
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif
 
    /*freopen(".in","r",stdin);
    freopen(".out","w",stdout);*/

    int t=1;
    //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 78788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 762 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 731 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 173 ms 184900 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 766 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 753 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 893 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 169 ms 164480 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 71 ms 69584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 309 ms 321364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -