Submission #480857

# Submission time Handle Problem Language Result Execution time Memory
480857 2021-10-18T12:26:48 Z Victor Burza (COCI16_burza) C++17
0 / 160
1000 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto& a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

vi s_graph[401], graph[401];
int n, k, md[401], p[401];

void dfs(int u, int d) {
    md[u] = d;
    if (d < k) trav(v, s_graph[u]) if (p[u] != v) {
            p[v] = u;
            dfs(v, d + 1);
            md[u] = max(md[u], md[v]);
            if (md[v] == k) graph[u].pb(v);
        }
}

vector<bitset<401>>dp(int u, int d) {
    vector<bitset<401>> sols;
    if(sz(graph[u]))sols.pb(bitset<401>());
    trav(v, graph[u]) if (v != p[u]) {
        vector<bitset<401>> vec = dp(v, d + 1);
        vector<bitset<401>> nxt;
        trav(sol, sols) trav(bs, vec) if (!(sol & bs).count())nxt.pb(sol|bs);
        sols.swap(nxt);
    }

    bitset<401> bs;
    bs[d]=1;
    sols.pb(bs);
    //cout<<"u = "<<u<<" d = "<<d<<" num sol = "<<sz(sols)<<endl;
    return sols;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    cin >> n >> k;
    rep(i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        s_graph[--u].pb(--v);
        s_graph[v].pb(u);
    }

    p[0] = 0;
    dfs(0, 0);
    if(sz(dp(0,0))<=1)cout<<"NE"<<endl;
    else cout<<"DA"<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1120 ms 517480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 989 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 962 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 827 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1000 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 977 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1104 ms 524292 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 819 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 784 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 962 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -