답안 #914397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914397 2024-01-21T23:19:58 Z vjudge1 Burza (COCI16_burza) C++17
160 / 160
52 ms 1548 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e9+7;

set<int> adj[401];
pair<int, int> cover[401];
vector<int> atdepth[401];
int maxdepth[401];
int dp[1<<20];
int leaves=0;
int x, y;

void prune(int a, int b, int c){
  maxdepth[a]=c;
  set<int> temp=adj[a];
  for(auto i: temp){
    if(i==b) continue;
    prune(i, a, c+1);
    maxdepth[a]=max(maxdepth[a], maxdepth[i]);
    if(maxdepth[i]<y) adj[a].erase(i);
  }
}

void dfs(int a, int b, int d){
  atdepth[d].push_back(a);
  cover[a]={LLONG_MAX/2, LLONG_MIN/2};
  bool flag=true;
  for(auto i: adj[a]){
    if(i==b) continue;
    flag=false;
    dfs(i, a, d+1);
    cover[a].first=min(cover[a].first, cover[i].first);
    cover[a].second=max(cover[a].second, cover[i].second);
  }
  if(flag) cover[a]={++leaves, leaves};
}

void solve(){
  cin>>x>>y;
  for(int i=0; i<x-1; i++){
    int a, b;
    cin>>a>>b;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  if(y>=20){
    cout<<"DA";
    return;
  }
  prune(1, 0, 0);
  dfs(1, 0, 0);
  for(int i=0; i<(1<<y); i++){
    for(int j=0; j<y; j++){
      if(i&(1<<j)){
        dp[i]=max(dp[i], dp[i^(1<<j)]);
        for(auto k: atdepth[j+1]){
          if(cover[k].first<=dp[i^(1<<j)]+1) dp[i]=max(dp[i], cover[k].second);
        }
      }
    }
  }
  if(dp[(1<<y)-1]==leaves || adj[1].empty()) cout<<"DA";
  else cout<<"NE";
}

signed main(){
  //freopen("in", "r", stdin); //freopen("out", "w", stdout);
  cin.tie(0)->sync_with_stdio(0);
  int t=1; //cin>>t;
  while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 52 ms 1364 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 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 41 ms 1360 KB Output is correct
2 Correct 36 ms 1364 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 39 ms 1336 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1376 KB Output is correct
2 Correct 38 ms 1408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 13 ms 628 KB Output is correct
2 Correct 39 ms 1528 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 36 ms 1548 KB Output is correct
2 Correct 38 ms 1364 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1372 KB Output is correct
2 Correct 37 ms 1320 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1360 KB Output is correct
2 Correct 45 ms 1400 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 42 ms 1528 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 600 KB Output is correct
2 Correct 38 ms 1340 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 46 ms 1540 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 908 KB Output is correct
2 Correct 43 ms 1536 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 18 ms 820 KB Output is correct
6 Correct 0 ms 348 KB Output is correct