답안 #398464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398464 2021-05-04T10:40:09 Z Radman_ Burza (COCI16_burza) C++14
0 / 160
1000 ms 22892 KB
//                  //
//     Radmanシ     //
//                 //
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

//#define int long long

typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
#define F first
#define S second

const int maxn=400+5,inf=1e9;
int dp[maxn][1<<20],mark[maxn];
vector<int> yal[maxn];
vector<pii> a[maxn];
int n,k,t=0;

pii dfs(int now,int d)
{
    mark[now]=1;
    if(d==k)
    {
        t++;
        a[k].push_back(pii(t,t));
        return pii(t,t);
    }
    int l=inf,r=0;
    int sizeee=yal[now].size();
    for(int i=0;i<sizeee;i++)
    {
        int next=yal[now][i];
        if(mark[next])
            continue;
        pii p=dfs(next,d+1);
        l=min(l,p.F);
        r=max(r,p.S);
    }
    if(pii(l,r)!=pii(inf,0))
        a[d].push_back(pii(l,r));
    return pii(l,r);
}

pii binary_search(int d,int h)
{
    int l=0,r=a[h].size();
    while(r-l>1)
    {
        int mid=(r+l)/2;
        if(a[h][mid].F<=d)
            l=mid;
        else
            r=mid;
    }
    return a[h][l];
}

int32_t main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        yal[u].push_back(v);
        yal[v].push_back(u);
    }
    if(k*k>=n)
    {
        cout<<"DA"<<endl;
        return 0;
    }
    dfs(1,0);
    /*for(int i=1;i<=k;i++)
    {
        for(int j=0;j<a[i].size();j++)
        {
            pii p=a[i][j];
            cout<<'['<<p.F<<','<<p.S<<']'<<' ';
        }
        cout<<endl;
    }*/
    for(int mask=0;mask<(1<<k);mask++)
        dp[0][mask]=1;
    for(int i=1;i<=t;i++)
    {
        for(int mask=1;mask<(1<<k);mask++)
        {
            for(int j=0;j<k;j++)
            {
                //cout<<i<<' '<<mask<<' '<<j<<endl;
                if(!((mask>>j)&1))
                    continue;
                pii p=binary_search(i,j+1);
                //cout<<'['<<p.F<<','<<p.S<<']'<<endl;
                //cout<<mask-(1<<j)<<endl;
                if(dp[p.F-1][mask-(1<<j)])
                    dp[i][mask]=1;
                //cout<<"DP = "<<dp[i][mask]<<endl;
            }
        }
    }
    int f=0;
    for(int mask=1;mask<(1<<k);mask++)
    {
        if(!dp[t][mask])
            continue;
        f=1;
        break;
    }
    if(f)
        cout<<"DA"<<endl;
    else
        cout<<"NE"<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 5740 KB Output is correct
2 Execution timed out 1100 ms 22680 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 21432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 22032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 709 ms 14188 KB Output is correct
2 Execution timed out 1088 ms 22696 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 22704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 22888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1100 ms 22876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 542 ms 11212 KB Output is correct
2 Execution timed out 1098 ms 21876 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 4472 KB Output is correct
2 Execution timed out 1093 ms 22892 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 748 ms 13808 KB Output is correct
2 Execution timed out 1097 ms 22540 KB Time limit exceeded
3 Halted 0 ms 0 KB -