# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098794 | Icelast | Burza (COCI16_burza) | C++17 | 1 ms | 456 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 1e9+9;
void solve(){
int n, k;
cin >> n >> k;
vector<vector<int>> adj(n+1);
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<ll> f(n+1);
auto dfs = [&](auto dfs, int u, int p, int len) -> void{
vector<ll> a;
if(len == k){
f[u] = INF;
return;
}
ll sum = 0;
for(int v : adj[u]){
if(v == p) continue;
dfs(dfs, v, u, len+1);
a.push_back(f[v]);
sum += f[v];
}
sort(a.begin(), a.end(), greater<ll>());
f[u] = INF;
for(int i = 0; i < a.size(); i++){
f[u] = min(f[u], sum-a[i]+i);
sum-=a[i];
}
if(a.empty()) f[u] = 0;
};
dfs(dfs, 1, 0, 0);
ll ans = f[1];
cout << "NE";
return;
if(ans == 0){
cout << "DA";
}else{
cout << "NE";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Compilation message (stderr)
# | 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... |