이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=405;
int n, k, u, v, s[nx], cnt, vs[nx], idx[nx], lvl[nx];
vector<int> d[nx];
void solve(int u, int p)
{
lvl[u]=lvl[p]+1;
if (d[u].size()==1) return s[u]=1, void();
pair<int, int> mx;
for (auto v:d[u]) if (v!=p) solve(v, u), mx=max(mx, {s[v], v});
idx[u]=mx.second;
pair<int, int> mx2;
for (auto v:d[u]) if (v!=p&&v!=mx.second) mx2=max(mx2, {s[v], v});
if (mx2.first!=0) s[u]=mx2.first+1;
else s[u]=1;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
solve(1, 1);
//for (int i=1; i<=n; i++) cout<<"debug "<<i<<' '<<idx[i]<<' '<<s[i]<<'\n';
vector<int> t;
t.push_back(1);
while (1)
{
pair<int, int> mx;
for (auto x:t) mx=max(mx, {s[x], x});
vs[idx[mx.second]]=1;
vector<int> tmp;
for (auto x:t) if (!vs[x]) for (auto v:d[x]) if (lvl[v]>lvl[u]) tmp.push_back(v);
if (tmp.empty()) break;
t=tmp;
cnt++;
}
if (cnt<k) cout<<"DA";
else cout<<"NE";
}
# | 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... |