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;
//#define int long long
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sp <<' '<<
#define pb push_back
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(a) for(auto el:a) cout<<el<<' '; cout<<endl;
#define contp(a) for(auto el:a) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;
#define DEBUG(x) cout<<#x sp ":" sp x<<endl;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef long long ll;
#define mid (l+r)/2
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
#define carp(x,y) ((x%MOD)*(y%+MOD))%MOD
const int MAXN=2e5+5;
const int MOD=998244353;
const int INF=1e9;
vi adj[MAXN];
int dp[MAXN];
void dfs(int nd,int ata,int h){
int mx,mx2;
mx=mx2=-1;
for(auto kom:adj[nd]){
if(kom==ata) continue;
dfs(kom,nd,h+1);
if(dp[kom]>mx){
swap(mx,mx2);
mx=dp[kom];
}
else if(dp[kom]>mx2){
mx2=dp[kom];
}
}
dp[nd]=mx2+1;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin>>n>>k;
FOR(i,n-1){
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
//dp on tree yapıcaz
dfs(1,-1,0);
if(dp[1]<k) cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
# | 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... |