Submission #1083805

#TimeUsernameProblemLanguageResultExecution timeMemory
1083805mmdrzadaBurza (COCI16_burza)C++17
0 / 160
1 ms596 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define sep ' ' #define F first #define S second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define kill(x) {cout << x << endl;return;} const int N = 500; const ll LLINF = 2e18; int n, k; int h[N]; int par[N]; int cnt[N]; vi adj[N]; // check MAXN // diffrence between extract and erase in multi set void set_io() { fastIO; // freopen("guard.in", "r", stdin); // freopen("guard.out", "w", stdout); } void dfs(int v = 0, int p = -1) { h[v] = (p == -1 ? 0 : h[p] + 1); par[v] = p; for(int neigh: adj[v]) { if (neigh == p) continue; dfs(neigh, v); cnt[v] += cnt[neigh]; } cnt[v] += (h[v] == k); } void solve() { cin >> n >> k; for(int i = 0, a, b ; i < n-1 ; i ++) cin >> a >> b, adj[--a].pb(--b), adj[b].pb(a); dfs(); set<pair<int, int>> p, q; q.insert({cnt[0], 0}); int ans = 0; while(true) { p.clear(); for(auto [x, u]: q) { if (h[u] == k) { cout << "NE" << endl; return; } for(int neigh: adj[u]) if (neigh != par[u]) p.insert({cnt[neigh], neigh}); } if (p.size() == 0) break; p.erase(*p.rbegin()); ans++; swap(p, q); } cout << (ans < k ? "DA" : "NE") << endl; } int main() { set_io(); solve(); return 0; }
#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...