Submission #653520

#TimeUsernameProblemLanguageResultExecution timeMemory
653520darshitjnBurza (COCI16_burza)C++14
0 / 160
2 ms340 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;i<n;i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define all(x) x.begin(), x.end()
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << " " << x << "\n";
#define INP(v) for(auto &x:v){cin >> x;}
#define OUT(v) for(auto &x:v){cout << x << " ";}
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const ll mod = 1000000007;
const ll N = 2e5;
const ll Fact_Length = 5e5 + 100;
//template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;

// A.find_by_order(k-1) // gives kth smallest element
// A.order_of_key(x) // no. of elements which are less than x

//Takes a&b as input and Returns : The power (a,b), (a^b)%mod
/*ll Power(ll base, ll expo)
{
   ll $result=1; base%=mod;
   while(expo) {   if(expo%2==1)  $result=($result*base)%mod;     base=(base*base)%mod;     expo/=2; }
   return $result;
}
 
// It give the modulo inverse of a, (1/a)%mod
ll Mod_Inv(ll $a) { return Power($a,mod-2); }
 
ll Factorial[Fact_Length];
// It make the above Factorial[i] = i! array
ll Make_Factorial()
{
   Factorial[0]=1;
   for(ll i=1;i<Fact_Length;i++) { Factorial[i]=(i*Factorial[i-1])%mod; } return 0;
}
ll Implement_Make_Factorial=Make_Factorial();      //To Implement Make_Factorial
 
// Takes n&r as input and Returns : nCr%mod
ll nCr(ll $n,ll $r)
{
   if($n<$r || $n<0 || $r<0) return 0;
   //if($n>Fact_Length) { cout<<"Error"<<endl; return; }
   ll $ans=(Factorial[$n]*Mod_Inv(Factorial[$r]))%mod;
   $ans=($ans*Mod_Inv(Factorial[$n-$r]))%mod;
   return $ans;
}*/

/*void seive(ll n){           
    for(ll i=2; i*i<=n; i++){
        if(a[i]==0){
            for(ll j=i; i*j<=n; j++){
                a[i*j] = 1;
            }
        }
    }
}*/

/*ll pw(ll a,ll b){
    if(b==0)return 1;
    ll t=pw(a,b/2);
    if(b%2)return ((a*t*t)%mod);
    else return ((t*t)%mod);
}
*/


void solve(){
    ll n,k; cin >> n >> k;
    vvl adj(n);
    ll a,b;
    fo(i,n-1){
        cin >> a >> b;
        adj[--a].pb(--b);
        adj[b].pb(a);
    }

    function <ll(ll,ll)> dfs = [&](ll i,ll prev){
         vl moves;
         for(auto x:adj[i]){
            if(x==prev)
               continue;
            moves.pb(dfs(x,i)+1);
         }
         if(moves.size()<=1){return 1ll;}
         sort(all(moves),greater<ll>());
         return moves[1];  
    };

    if(dfs(0,-1)<=k){cout << "DA\n";}
    else{cout << "NE\n";}
}

int main()
{
    //ifstream fin("input.txt");
    //ofstream fout("output.txt");
    //freopen("input.in","r",stdin); 
    //freopen("output.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll darshit = 1;
	//cin >> darshit;
    
    for(ll i=1;i<=darshit;i++)
    {
    //cout <<"Case #" << i <<": ";  
    solve();
    }


	return 0;
}

Compilation message (stderr)

burza.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...