Submission #1343956

#TimeUsernameProblemLanguageResultExecution timeMemory
1343956OwstinBurza (COCI16_burza)C++20
0 / 160
1 ms344 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define pb push_back
#define all(x) begin(x), end(x)
#define umap unordered_map
#define space " "
#define TEST_CASES int a; cin >> a; for (int i = 0; i < a; i++) {solve(); cout << endl;}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, k; cin >> n >> k;
    vector<vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int x, y; cin >> x >> y; x--; y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    vector<int> dp(n, 1);
    auto dfs = [&] (auto &&self, int node, int parent) -> void {
        vector<int> goes;
        for (auto x : adj[node]) {
            if (x == parent) {
                continue;
            }
            self(self, x, node);
            goes.pb(dp[x]);
        }
        sort(all(goes));
        if (goes.size() >= 2) {
            dp[node] = goes[goes.size() - 2] + 1;
        }
    };
    dfs(dfs, 0, -1);
    cout << (dp[0] <= k ? "DA" : "NE");
}

int main() {
    FAST_IO;
    //freopen("guard.in", "r", stdin);
    //freopen("guard.out", "w", stdout);
    //TEST_CASES;
    solve(); cout << endl;
    /*int a; cin >> a;
    for (int i = 1; i <= a; i++){
        cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }*/
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...