답안 #674565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674565 2022-12-25T07:10:22 Z Nicolas125841 Burza (COCI16_burza) C++14
128 / 160
505 ms 18412 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define YES "DA"
#define NO "NE"
 
vector<vector<int>> layers;
vector<int> ways;
unordered_map<int, bitset<400>> coverage;
 
bitset<400> dfs(vector<vector<int>> &mp, int n, int p, int d, int k){
    if(layers.size() == d){
        layers.push_back(vector<int>());
        ways.push_back(0);
    }
 
    if(d == k){
        coverage[n] |= 1;
        coverage[n] <<= layers[d].size();
    }
 
    layers[d].push_back(n);
 
    for(int v : mp[n]){        
        if(v != p){
            bitset<400> res = dfs(mp, v, n, d+1, k);
 
            if(layers.size() > k && d < k)
                coverage[n] |= res;           
        }
    }
 
    if(coverage[n] != 0)
        ways[d]++;

    return coverage[n];
}
 
int main(){
    cin.tie(NULL)->sync_with_stdio(false);
 
    int n, k;
    cin >> n >> k;
 
    vector<vector<int>> mp(n, vector<int>());    
 
    for(int i = 0; i < n-1; i++){
 
        int u, v;
        cin >> u >> v;
 
        mp[--u].push_back(--v);
        mp[v].push_back(u);
 
    }
    
    dfs(mp, 0, -1, 0, k);
    
    if(layers.size() <= k)
        cout << YES << "\n";
    else{
        unordered_set<bitset<400>> cur, prev = {bitset<400>()};
        bool g = false;
 
        for(int i = 1; i <= k; i++){
            for(bitset<400> bs : prev){
                for(int v : layers[i]){
                    if(coverage[v] == 0)
                        continue;

                    if((coverage[v] & bs) == 0 && cur.size() <= 100100){
                        cur.insert(coverage[v] | bs);

                        if((coverage[v] | bs).count() == layers[k].size())
                            g = true;
                    }                
                }
            }
 
            swap(cur, prev);
            cur.clear();
        }
 
        cout << (g ? YES : NO) << "\n";
    }
 
    
}

Compilation message

burza.cpp: In function 'std::bitset<400> dfs(std::vector<std::vector<int> >&, int, int, int, int)':
burza.cpp:13:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |     if(layers.size() == d){
      |        ~~~~~~~~~~~~~~^~~~
burza.cpp:29:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |             if(layers.size() > k && d < k)
      |                ~~~~~~~~~~~~~~^~~
burza.cpp: In function 'int main()':
burza.cpp:60:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     if(layers.size() <= k)
      |        ~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2132 KB Output is correct
2 Correct 219 ms 4756 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 344 ms 15796 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 4652 KB Output is correct
2 Correct 213 ms 4756 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 221 ms 4648 KB Output is correct
6 Incorrect 97 ms 9904 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 4644 KB Output is correct
2 Correct 210 ms 4780 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 398 ms 18384 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1480 KB Output is correct
2 Correct 209 ms 4760 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 46 ms 9476 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 4668 KB Output is correct
2 Correct 203 ms 4648 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 505 ms 18412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 4696 KB Output is correct
2 Correct 203 ms 4752 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 24 ms 4708 KB Output is correct
6 Correct 64 ms 9624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 4652 KB Output is correct
2 Correct 209 ms 4640 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 219 ms 4816 KB Output is correct
6 Correct 412 ms 18388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1536 KB Output is correct
2 Correct 210 ms 4648 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 53 ms 9604 KB Output is correct
6 Correct 252 ms 13428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 852 KB Output is correct
2 Correct 211 ms 4684 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 80 ms 10316 KB Output is correct
6 Correct 287 ms 14752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 2528 KB Output is correct
2 Correct 197 ms 4648 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 98 ms 2512 KB Output is correct
6 Correct 1 ms 340 KB Output is correct