답안 #1086602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086602 2024-09-11T06:24:27 Z chaoslong Burza (COCI16_burza) C++14
160 / 160
44 ms 15064 KB
// Calm down.
// Think three times, code twice.
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;

int n, k, mx_cover[N];
map<int, int> lost;
vector<int> a[N], cut[N], depth[N];
vector<pii> intervals;

void dfs(int u, int pre, int d) {
    depth[d].pb(u);
    if(d == k) {
        lost[u] = lost.size();
//        cout << u << " " << last[u] << "\n";
        cut[u] = {u};
        return;
    }
    for(int v: a[u]) {
        if(v == pre) continue;
        dfs(v, u, d+1);
//        cout << u << " " << v << "\n";
        cut[u].insert(cut[u].end(), cut[v].begin(), cut[v].end());
    }
}

void to_nho_cau() {
    cin >> n >> k;
    if(k * k >= n) {
        cout << "DA\n";
        return;
    }
    forr(i, 1, n-1) {
        int u, v; cin >> u >> v;
        a[u].pb(v);
        a[v].pb(u);
    }
    dfs(1, 0, 0);
//    forr(i, 1, n) {
//        cout << i << ": \n";
//        for(int v: cut[i]) cout << v << " ";
//        cout << "\n";
//    }
    forr(i, 1, n) {
        if(cut[i].empty()) {
            intervals.pb({-1, -1});
            continue;
        }
        intervals.pb({lost[cut[i].front()] + 1, lost[cut[i].back()] + 1});
    }
    mx_cover[0] = 0;
    forf(ss, 1, mask(k)) {
        forr(i, 0, k-1) {
            if(bit(ss, i)) {
                int prev = mx_cover[ss ^ mask(i)];
//                cout << ss << " " << i << " " << prev << "\n";
                for(int v: depth[i+1]) {
                    if(intervals[v-1].st <= prev + 1) {
//                        cout << ss << " " << i << " " << prev << " " << v << "\n";
                        mx_cover[ss] = max(mx_cover[ss], intervals[v-1].nd);
                    }
                }
            }
        }
        if(mx_cover[ss] == lost.size()) {
            cout << "DA\n";
            return;
        }
    }
    cout << "NE\n";
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef LOCAL
        freopen(file".inp","r",stdin);
        freopen(file".out","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) to_nho_cau();
}
/*
1.self check:
2.long long
3.size of array
4.code for testing
5.initializing
6.modulo number
*/
/**
  ∧__∧
(`•ω• )づ__∧
(つ  /( •ω•。)
  しーJ (nnノ) pat pat
**/
/**  /\_/\
*   (= ._.)
*   / >☕ \>💻
**/

Compilation message

burza.cpp:119:9: warning: "/*" within comment [-Wcomment]
  119 | /**  /\_/\
      |          
burza.cpp: In function 'void to_nho_cau()':
burza.cpp:87:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         if(mx_cover[ss] == lost.size()) {
      |            ~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14424 KB Output is correct
2 Correct 35 ms 14936 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14388 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 14932 KB Output is correct
2 Correct 34 ms 14932 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 34 ms 14964 KB Output is correct
6 Correct 6 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 14932 KB Output is correct
2 Correct 37 ms 14864 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 7 ms 14400 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14684 KB Output is correct
2 Correct 37 ms 14932 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14436 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 14936 KB Output is correct
2 Correct 34 ms 14928 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14436 KB Output is correct
5 Correct 7 ms 14564 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 14928 KB Output is correct
2 Correct 35 ms 14932 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14560 KB Output is correct
6 Correct 7 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 14936 KB Output is correct
2 Correct 34 ms 15048 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 33 ms 14892 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14720 KB Output is correct
2 Correct 37 ms 15064 KB Output is correct
3 Correct 8 ms 14512 KB Output is correct
4 Correct 6 ms 14424 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14424 KB Output is correct
2 Correct 44 ms 14992 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14556 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14684 KB Output is correct
2 Correct 35 ms 14976 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14552 KB Output is correct
5 Correct 21 ms 14636 KB Output is correct
6 Correct 6 ms 14424 KB Output is correct