Submission #480842

# Submission time Handle Problem Language Result Execution time Memory
480842 2021-10-18T11:13:01 Z Victor Burza (COCI16_burza) C++17
0 / 160
1000 ms 344 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;

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

void dfs(int u, int d) {
    trav(v, graph[u]) if (v != p[u]) {
        p[v] = u;
        dfs(v, d + 1);
    }
}

set<list<int>> memo[401];

void dp(int depth, list<int> nodes) {
    if (depth >= k) return;
    if (memo[depth].count(nodes)) return;

    list<int> nxt;
    trav(u, nodes) trav(v, graph[u]) if (p[u] != v) nxt.push_back(v);
    if (sz(nxt) <= 1) {
        cout << "DA" << endl;
        exit(0);
    }

    auto it = nxt.begin();
    rep(i, 0, sz(nxt)) {
        int val=*it;
        it=nxt.erase(it);
        dp(depth+1,nxt);
        nxt.insert(it,val);
    }
}

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;
        graph[--u].pb(--v);
        graph[v].pb(u);
    }

    list<int>l;
    l.pb(0);
    dfs(0, 0);
    dp(0,l);

    cout << "NE" << endl;
    return 0;
}

Compilation message

burza.cpp: In function 'void dp(int, std::__cxx11::list<int>)':
burza.cpp:5:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::list<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i, a, b) for (int i = (a); i < (b); ++i)
      |                                          ^
burza.cpp:54:5: note: in expansion of macro 'rep'
   54 |     rep(i, 0, sz(nxt)) {
      |     ^~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1100 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -