이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define PB push_back
#define N 405
using namespace std;
int n, k;
vector<int> g[N];
int DFS(int u, int p)
{
int f1 = 0, f2 = 0;
for (auto v : g[u])
{
if (v == p) continue;
int z = DFS(v, u);
if (z >= f1)
{
f2 = f1;
f1 = z;
}
else if (z > f2)
f2 = z;
}
return f2 + 1;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> k;
for (int i = 1; i < n; i++)
{
int u, v; cin >> u >> v;
g[u].PB(v); g[v].PB(u);
}
int res = DFS(1, -1);
if (res <= 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... |