# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010908 | WhiteZeros | Burza (COCI16_burza) | C++17 | 32 ms | 936 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define task "coci1617_r2_burza"
const int N = 4e2 + 1 , M = 20 , inf = 1e9 ;
int n , k , stt = 0;
vector<int> D[N] , depth[M] , cover[N];
int dp[1 << M] , tin[N] , tout[N] , pos[N];
void maximize(int &a , int b){
if(a < b) a = b ;
}
void minimize(int &a , int b){
if(a > b) a = b ;
}
void dfs(int u , int p , int h){
depth[h].push_back(u) ;
if(h == k){
tin[u] = tout[u] = ++stt ;
return ;
}
for(int v : D[u]){
if(v == p) continue;
dfs(v , u , h + 1);
minimize(tin[u] , tin[v]) ;
maximize(tout[u] , tout[v]) ;
}
}
int main()
{
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
if(ifstream(task".INP")){
freopen(task".INP","r",stdin) ;
freopen(task".OUT","w",stdout) ;
}
cin >> n >> k ;
if(k * k >= n){
cout <<"DA" ;
return 0;
}
for(int i = 1 ; i <= n ; i++) tin[i] = inf ;
for(int i = 1 ; i < n ; i++){
int u , v ;
cin >> u >> v ;
D[u].push_back(v) ;
D[v].push_back(u) ;
}
dfs(1 , 0 , 0) ;
dp[0] = 0 ;
for (int i = 1; i < (1 << k); i++) {
for (int j = 0; j < k; j++) {
if ((i >> j & 1)) {
int prev = dp[i ^ (1 << j)];
for (int v : depth[j + 1]) {
if (tin[v] <= prev + 1) {
dp[i] = max(dp[i], tout[v]);
}
}
}
}
if (dp[i] == stt) {
cout << "DA";
return 0;
}
}
cout << "NE";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |