답안 #242766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242766 2020-06-29T09:30:15 Z Vimmer Burza (COCI16_burza) C++14
160 / 160
144 ms 87072 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 2> a2;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


vector <int> g[405], vr;

int h[405], n, k, mxh[405], in[405], out[405];

bool f[405][(1 << 20)];

void rec(int v, int p)
{
    if (p != -1) h[v] = h[p] + 1;

    mxh[v] = h[v];

    if (h[v] == k) return;

    for (auto it : g[v])
    {
        if (it == p) continue;

        rec(it, v);

        mxh[v] = max(mxh[v], mxh[it]);
    }
}

void dfs(int v, int p)
{
    in[v] = sz(vr);

    vr.pb(v);

    for (auto it : g[v])
    {
        if (it == p || mxh[it] != k) continue;

        dfs(it, v);
    }
    out[v] = sz(vr);
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;

    if (k >= 20) {cout << "DA" << endl; exit(0);}

    for (int i = 1; i < n; i++)
    {
        int x, y;

        cin >> x >> y;

        g[x].pb(y);

        g[y].pb(x);
    }

    rec(1, -1);

    dfs(1, -1);

    for (int i = 0; i < (1 << 20); i++) f[sz(vr)][i] = 1;

    for (int i = sz(vr) - 1; i >= 0; i--)
      for (int msk = 0; msk < (1 << (k + 1)); msk++)
      {
          int v = vr[i];

          if (h[v] < k)
          {
              f[i][msk] = f[i + 1][msk];

              if (f[i][msk]) continue;
          }

          if ((1 << h[v]) & msk) continue;

          f[i][msk] = f[out[v]][msk | (1 << h[v])];
      }

    if (!f[1][0]) cout << "NE" << endl;
      else cout << "DA" << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 10880 KB Output is correct
2 Correct 144 ms 87072 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 7 ms 3584 KB Output is correct
6 Correct 5 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 84216 KB Output is correct
2 Correct 133 ms 84856 KB Output is correct
3 Correct 4 ms 404 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 127 ms 85112 KB Output is correct
6 Correct 6 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 84900 KB Output is correct
2 Correct 129 ms 84668 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 7 ms 3072 KB Output is correct
6 Correct 6 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 21756 KB Output is correct
2 Correct 133 ms 87032 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 5 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 82296 KB Output is correct
2 Correct 137 ms 84728 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 3584 KB Output is correct
6 Correct 6 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 84856 KB Output is correct
2 Correct 133 ms 83576 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 7 ms 3456 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 86264 KB Output is correct
2 Correct 130 ms 84088 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 138 ms 84448 KB Output is correct
6 Correct 6 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 20096 KB Output is correct
2 Correct 132 ms 86264 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 9856 KB Output is correct
2 Correct 129 ms 86136 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 38392 KB Output is correct
2 Correct 138 ms 86264 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 60 ms 38776 KB Output is correct
6 Correct 6 ms 2304 KB Output is correct