이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define i2 array<int,2>
using namespace std;
const int N = 510;
const int oo = 2e9;
vector<int> g[N];
vector<i2> vc, nw;
int n, k, f[N], ht[N], mx_ht[N], cnt[N], pre[N];
void dfs(int v, int pr){
mx_ht[v] = ht[v];
if (ht[v] == k){
cnt[v] = 1;
f[v] = oo;
return;
}
for (int u : g[v]){
if (u == pr) continue;
ht[u] = ht[v] + 1;
pre[u] = v;
dfs(u, v);
mx_ht[v] = max(mx_ht[v], mx_ht[u]);
cnt[v] += cnt[u];
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k;
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
dfs(0, -1);
vc.clear();
for (int u : g[0])
if (cnt[u] > 0)
vc.PB({cnt[u], u});
for (int it = 0; it < k && sz(vc) > 0; it++){
sort(all(vc));
reverse(all(vc));
nw.clear();
for (int it = 1; it < sz(vc); it++){
int v = vc[it][1];
for (int u : g[v]){
if (u == pre[v]) continue;
if (cnt[u] > 0)
nw.PB({cnt[u], u});
}
}
vc = nw;
}
cout << (sz(vc) == 0 ? "DA\n" : "NE\n");
return 0;
}
| # | 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... |