답안 #166652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166652 2019-12-03T11:46:52 Z egekabas Burza (COCI16_burza) C++14
0 / 160
3 ms 632 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n, k;
vector<ll> g[1009];
ll d[1009];
void calcdepth(ll v, ll p){
    if(p != -1 && g[1].size() == 1)
        return;
    for(auto u : g[v]){
        if(u == p)
            continue;
        calcdepth(u, v);
        d[v] = max(d[v], d[u]);
    }
    ++d[v];
}
ll dfs(ll v, ll p, ll cur){
    if(d[v] + cur < k){
        return 1e9;
    }
    if(cur == k){
        return 0;
    }
    vector<ll> vec;
    for(auto u : g[v]){
        if(u == p)
            continue;
        vec.pb(dfs(u, v, cur+1));
    }
    sort(vec.begin(), vec.end());
    ll c = 0;
    for(auto u : vec){
        if(c > u){
            return 0;
        }
        ++c;   
    }
    return vec[0] + 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> k;
    for(ll i = 0; i < n-1; ++i){
        ll t1, t2;
        cin >> t1 >> t2;
        g[t1].pb(t2);
        g[t2].pb(t1);
    }
    calcdepth(1, -1);
    if(dfs(1, -1, 0) > 0)
        cout << "DA\n";
    else
        cout << "NE\n";
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -