Submission #166824

# Submission time Handle Problem Language Result Execution time Memory
166824 2019-12-04T08:25:41 Z Atill83 Burza (COCI16_burza) C++14
0 / 160
5 ms 3192 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3000;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, k;
vector<int> adj[MAXN];
ll d[MAXN][MAXN];
bool did[MAXN][MAXN];
int dep[MAXN];
priority_queue<int, vector<int>, greater<int>> q;

ll dp(int a, int g, int par){
    //cout<<a<<" "<<g<<endl;
    if(did[a][g]) return d[a][g];
    did[a][g] = 1;
    if(a != 1 && adj[a].size() == 1){
        return d[a][g] = 0;
    }else{
        d[a][g] = INF;
        int many = min(g, (a == 1 ? (int)adj[a].size() : (int)adj[a].size() - 1));
        if(g > many){
            return d[a][g] = 0;
        }
        for(int i = 0; i <= many; i++){
            for(int j = 0; j < (int)adj[a].size(); j++){
                int cur = adj[a][j];
                if(cur == par) continue;
                q.push(dp(cur, g - i + 1, a));
                /*if(a == 2 && dp(cur, g - i + 1, a) == 0){
                    cout<<a<<" "<<cur<<endl;
                }*/
                //if(a == 1)
                //cout<<"control"<<endl;
            }
            for(int j = 0; j < i; j++){
                if(!q.empty())
                q.pop();
            }
            if(q.empty()){
                d[a][g] = 0;
            }else{
                d[a][g] = min(d[a][g], (ll)q.top() + 1);
            }
            while(!q.empty()) q.pop();
        }
        return d[a][g];
    }
}




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>k;

    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    //cout<<dp(1, 1, -1)<<endl;
    cout<<((dp(1, 1, -1) < k) ? "DA" : "NE")<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -