#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 2e5+3, oo = 1e9;
int choice[mxN],d[mxN],N,D, minput[mxN];
vi adj[mxN], ans;
void dfs(int at, int from) {
choice[at]=at;
minput[at]=oo;
for(int to : adj[at]) if(to!=from) {
d[to] = d[at]+1;
dfs(to,at);
minput[at] = min(minput[at],minput[to]+1);
if(choice[to]) {
if((d[choice[to]]-d[at])*2>=D) {
ans.push_back(choice[to]);
minput[at] = min(minput[at], d[choice[to]]-d[at]);
} else if(d[choice[to]]>d[choice[at]]) {
choice[at] = choice[to];
}
}
}
int got = d[choice[at]]-d[at];
if(got+minput[at]<D) {
choice[at]=0;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> D;
for(int i=0;i<N-1;++i) {
int u,v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,0);
if(choice[1]) ans.push_back(choice[1]);
cout << ans.size() << '\n'; //<< ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |