Submission #335338

# Submission time Handle Problem Language Result Execution time Memory
335338 2020-12-12T02:07:39 Z HynDuf Burza (COCI16_burza) C++11
160 / 160
26 ms 3180 KB
#include <bits/stdc++.h>

#define task "B"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
int n, K, st[401], ed[401], neu, dep[401];
vi g[401];
bool dp[400][1 << 19];
void dfs(int u, int p)
{
    if (dep[u] == K)
    {
        st[u] = ed[u] = ++neu;
        return;
    }
    st[u] = 1e9, ed[u] = 0;
    for (int v : g[u]) if (v != p)
    {
        dep[v] = dep[u] + 1;
        dfs(v, u);
        st[u] = min(st[u], st[v]);
        ed[u] = max(ed[u], ed[v]);
    }
}
vii qu[401];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> K;
    rep(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].eb(v);
        g[v].eb(u);
    }
    if (K * K >= n)
    {
        cout << "DA";
        return 0;
    }
    dfs(1, 0);
    rep(i, 2, n) if (st[i] != 1e9) qu[st[i]].eb(ed[i], dep[i] - 1);
    dp[0][0] = 1;
    rep(i, 0, neu - 1) rep(x, 0, (1 << K) - 1) if (dp[i][x]) for (ii &v : qu[i + 1]) if (!(x >> v.S & 1)) dp[v.F][x | (1 << v.S)] = 1;
    bool ok = 0;
    rep(x, 0, (1 << K) - 1) ok |= dp[neu][x];
    cout << (ok ? "DA" : "NE");
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 876 KB Output is correct
2 Correct 18 ms 2412 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2668 KB Output is correct
2 Correct 16 ms 2412 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 23 ms 2924 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2668 KB Output is correct
2 Correct 18 ms 2412 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1260 KB Output is correct
2 Correct 26 ms 3180 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2156 KB Output is correct
2 Correct 20 ms 2924 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2688 KB Output is correct
2 Correct 19 ms 2668 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2796 KB Output is correct
2 Correct 20 ms 2780 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 19 ms 2924 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1260 KB Output is correct
2 Correct 20 ms 2668 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 21 ms 2796 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1644 KB Output is correct
2 Correct 21 ms 2796 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 11 ms 1644 KB Output is correct
6 Correct 1 ms 620 KB Output is correct