Submission #166661

#TimeUsernameProblemLanguageResultExecution timeMemory
166661egekabasBurza (COCI16_burza)C++14
128 / 160
3 ms532 KiB
#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[v].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; ll t2 = dfs(u, v, cur+1); vec.pb(t2); } 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); } if(n == 1){ cout << "NE\n"; return 0; } calcdepth(1, -1); if(dfs(1, -1, 0) > 0) cout << "DA\n"; else cout << "NE\n"; }
#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...