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 <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int t = 1;
const ll M = 1e9 + 7;
ll mod_add(ll a, ll b){
return ((a%M) + (b %M))%M;
}
ll mod_mul(ll a, ll b){
return ((a%M)*(b%M))%M;
}
const ll MAX = 1e18;
void dfs(int s, int p , vector<int> adj[] , vector<int> &dp){
int child = 0 , max1 = 0 , max2 = 0;
for(auto x: adj[s]){
if(x != p){
child++;
dfs(x, s, adj , dp);
if(max1 < dp[x]){
max2 = max1;
max1 = dp[s];
}
else{
max2 = max(dp[x] , max2);
}
}
}
if(child <=1){
dp[s] = 0;
}
else{
dp[s] = 1 + max2;
}
}
void solve(){
int n , k ; cin>>n>>k;
vector<int> adj[n+1];
for(int i = 0;i<n ; i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<int> dp(n + 1);
dfs(1,-1,adj,dp);
if(dp[1] < k){
cout<<"DA";
}
else{
cout<<"NE";
}
}
int main(){
// freopen("input.txt" , "r" , stdin);
// freopen("output.txt" , "w", stdout);
// cin>>t;
while(t--){
solve();
}
}
# | 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... |