답안 #242769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242769 2020-06-29T09:38:13 Z Vimmer Burza (COCI16_burza) C++14
160 / 160
156 ms 96632 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];

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);

    char f[sz(vr) + 1][(1 << (k + 1))];

    for (int i = 0; i <= sz(vr); i++)
        for (int msk = 0; msk < (1 << (k + 1)); msk++) f[i][msk] = 'b';

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

    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] == 'a') continue;
          }

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

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

    if (f[1][0] == 'b') cout << "NE" << endl;
      else cout << "DA" << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 9728 KB Output is correct
2 Correct 151 ms 96084 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 91984 KB Output is correct
2 Correct 150 ms 91896 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 149 ms 92408 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 92512 KB Output is correct
2 Correct 144 ms 92280 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 22784 KB Output is correct
2 Correct 151 ms 96632 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 88440 KB Output is correct
2 Correct 149 ms 91768 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 92920 KB Output is correct
2 Correct 149 ms 90360 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 93944 KB Output is correct
2 Correct 156 ms 91128 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 143 ms 90872 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 20224 KB Output is correct
2 Correct 147 ms 94756 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 8576 KB Output is correct
2 Correct 152 ms 94840 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 39552 KB Output is correct
2 Correct 148 ms 95096 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 71 ms 40312 KB Output is correct
6 Correct 5 ms 384 KB Output is correct