답안 #501385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501385 2022-01-03T02:25:01 Z Dirii Burza (COCI16_burza) C++14
160 / 160
61 ms 51096 KB
// #pragma GCC target("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define cll const ll
#define lp(a, b, c) for(ll a = b; a <= c; ++a)
#define lpd(a, b, c) for(ll a = b; a >= c; --a)
#define vec(a) vector<a>
#define pp(a, b) pair<a, b>
#define EACHCASE lpd(cs, read(), 1)
#define Fname "f"
using namespace std;

template <typename T> inline void Read(T &x){
    x = 0; char c;
    ll dau = 1;
    while(!isdigit(c = getchar())) if(c == '-') dau = -1;
    do{
        x = x * 10 + c - '0';
    } while (isdigit(c = getchar()));
    x *= dau;
}

ll read(){
    ll tmp;
    cin >> tmp;
    return tmp;
}

void giuncute(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void OF(){
    if(fopen(Fname".inp", "r")){
        freopen(Fname".inp", "r", stdin);
        freopen(Fname".out", "w", stdout);
    } else if(fopen(Fname".in", "r")){
        freopen(Fname".in", "r", stdin);
        freopen(Fname".out", "w", stdout);
    }
}

#define yes "DA"
#define no "NE"

cll mxn = 406;
ll n, k, depth[mxn] = {0}, leaves[mxn] = {0}, totleaf = 1;
int dp[mxn][1 << 20];
vec(ll) g[mxn];
pp(ll, ll) range[mxn];
vec(pp(ll, ll)) ed_range[mxn];
bool isLeaf[mxn] = {0};

void init(ll u, ll p){
    if(depth[u] == k - 1){
        leaves[u] = totleaf;
        range[u] = {totleaf, totleaf + 1};
        ++totleaf;
        isLeaf[u] = 1;
        ed_range[range[u].second].push_back({range[u].first, depth[u]});
        return;
    }
    range[u].first = totleaf;
    for(ll v : g[u]){
        if(v == p) continue;
        depth[v] = depth[u] + 1;
        init(v, u);
    }
    range[u].second = totleaf;
    if(u != 1)
        ed_range[range[u].second].push_back({range[u].first, depth[u]});
}

bool sol(ll ed, ll mask){
    if(ed == 1) return 1;
    if(~dp[ed][mask]) return dp[ed][mask];
    int &cur = dp[ed][mask];
    for(auto i : ed_range[ed]){
        if((mask & (1 << i.second)) && sol(i.first, mask ^ (1 << i.second))){
            return cur = 1;
        }
    }
    return cur = 0;
}

int main(){
    giuncute();
    #ifndef ONLINE_JUDGE
    OF();
    #endif
    cin >> n >> k;
    lp(i, 1, n - 1){
        static ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if(k * k >= n) return cout << yes, 0;
    depth[1] = -1;
    init(1, -1);
    lp(i, 1, totleaf) lp(j, 0, (1 << k) - 1) dp[i][j] = -1;
    cout << (sol(totleaf, (1 << k) - 1) ? yes : no);
}

Compilation message

burza.cpp: In function 'bool sol(long long int, long long int)':
burza.cpp:83:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   83 |             return cur = 1;
      |                    ~~~~^~~
burza.cpp:86:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   86 |     return cur = 0;
      |            ~~~~^~~
burza.cpp: In function 'void OF()':
burza.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(Fname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(Fname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(Fname".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(Fname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7256 KB Output is correct
2 Correct 56 ms 49604 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 2252 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 43320 KB Output is correct
2 Correct 51 ms 41676 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 28 ms 42268 KB Output is correct
6 Correct 1 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 42816 KB Output is correct
2 Correct 40 ms 42828 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 17248 KB Output is correct
2 Correct 37 ms 51096 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 36496 KB Output is correct
2 Correct 61 ms 40720 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 2132 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 45380 KB Output is correct
2 Correct 43 ms 39668 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 2252 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 43860 KB Output is correct
2 Correct 42 ms 41164 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 16 ms 38608 KB Output is correct
6 Correct 1 ms 1752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 12776 KB Output is correct
2 Correct 45 ms 46924 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5452 KB Output is correct
2 Correct 58 ms 47436 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 1 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 16984 KB Output is correct
2 Correct 42 ms 48020 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 8 ms 18008 KB Output is correct
6 Correct 1 ms 1104 KB Output is correct