이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ii = pair<int, int>;
#define fi first
#define se second
#define pb push_back
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x > y + eps) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x + eps < y) {
            x = y;
            return true;
        } else return false;
    }
const int N = 1e5 + 7, oo = 1e9 + 7;
int n, k, ans;
vector<int> adj[N];
void dfs(int u, int par = -1, int len = 0) {
    maximize(ans, len);
    int mx = -1, node = -1;
    for (int v: adj[u]) if (v != par)
        if (maximize(mx, sz(adj[v]))) node = v;
    for (int v: adj[u]) if (v != par && v != node) {
        dfs(v, u, len + 1);
    }
}
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
//#ifndef ONLINE_JUDGE
//   freopen("test.inp", "r", stdin);
//   freopen("test.out", "w", stdout);
//#endif
    cin >> n >> k;
    for (int i = 0, u, v; i < n - 1; i++) {
        cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    } dfs(1);
    cout << (ans >= k ? "NE" : "DA");
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |