Submission #782381

# Submission time Handle Problem Language Result Execution time Memory
782381 2023-07-13T21:43:54 Z vgoofficial Burza (COCI16_burza) C++14
0 / 160
1000 ms 185392 KB
//Some wierd BFS can also pass(?)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define siz(x) (int)x.size()
#define pb push_back
#define all(x) x.begin(), x.end()
//===========================================
const int MAX = 405;
vi adj[MAX];
int p[MAX], dep[MAX], depb[MAX];
set<vi> vis;
 
void dfs(int v){
    for (int u: adj[v]){
        if (u == p[v]) continue;
        p[u] = v;
        dep[u] = dep[v]+1;
        dfs(u);
        depb[v] = max(depb[v], depb[u]+1);
    }
}
 
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    queue<vi> q; q.push({1});
    while (siz(q)){
        auto vec = q.front(); q.pop();
        if (vec.empty()){
            cout << "DA\n";
            return 0;
        }
        int rem = k-dep[vec[0]];
        vi vv;
        for (int v: vec){
            for (int u: adj[v]){
                if (u == p[v]) continue;
                if (depb[u]+1 >= rem) vv.pb(u);
            }
        }
        if (siz(vv) > rem) continue;
        for (int i = 0; i < siz(vv); i++){
            swap(vv[i], vv.back());
            vector<int> temp = vv; temp.pop_back();
            if (!vis.count(temp)){
                q.push(temp);
                vis.insert(temp);
            }
            swap(vv[i], vv.back());
        }
    }
    cout << "NE\n";
}
# Verdict Execution time Memory Grader output
1 Correct 891 ms 48392 KB Output is correct
2 Execution timed out 1087 ms 183908 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 184612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 184724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 111052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 185392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 181944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 184688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 108116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 926 ms 48344 KB Output is correct
2 Execution timed out 1086 ms 184616 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 140112 KB Time limit exceeded
2 Halted 0 ms 0 KB -