답안 #166816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166816 2019-12-04T07:47:47 Z Atill83 Burza (COCI16_burza) C++14
0 / 160
4 ms 1704 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) 4e2+5;

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] = 1;
    }else{
        d[a][g] = INF;
        int many = min(g, (a == 1 ? (int)adj[a].size() : (int)adj[a].size() - 1));
        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 == 1)
                //cout<<"control"<<endl;
            }
            for(int j = 0; j < i; j++){
                if(!q.empty())
                q.pop();
            }
            if(q.empty()){
                d[a][g] = 1;
            }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) <= k) ? "DA" : "NE")<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -