답안 #1115705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115705 2024-11-20T20:34:26 Z lgmulti Burza (COCI16_burza) C++14
0 / 160
2 ms 1616 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long

const ll MAXN=405;

ll n,k;
ll g[MAXN][MAXN];
vector<ll> son[MAXN];
ll father[MAXN];

void dfs(ll x){
    ll i,j;
    for(i=1;i<=n;i++){
        if(g[x][i] && father[x]!=i){
            father[i]=x;
            son[x].push_back(i);
            dfs(i);
        }
    }
}

ll maxtravtime=0;

void dfs2(ll x){
    ll i,j;
    maxtravtime++;
    ll sonWithTheMostGrandson=0,sonWithTheSecondMostGrandson=0;
    for(i=0;i<son[x].size();i++){
        if(son[son[x][i]].size()>=son[sonWithTheMostGrandson].size()){
            sonWithTheSecondMostGrandson=sonWithTheMostGrandson;
            sonWithTheMostGrandson=son[x][i];
        }
        else if(son[son[x][i]].size()>=son[sonWithTheSecondMostGrandson].size())
            sonWithTheSecondMostGrandson=son[x][i];
    }

    //cout<<x<<": "<<sonWithTheMostGrandson<<' '<<sonWithTheSecondMostGrandson<<endl;

    if(sonWithTheSecondMostGrandson==0)
        return;
    dfs2(sonWithTheSecondMostGrandson);
}

int main(){
    ll i,j;
    cin>>n>>k;
    for(i=1;i<n;i++){
        ll u,v;
        cin>>u>>v;
        g[u][v]=g[v][u]=1;
    }

    dfs(1);

    dfs2(1);

    cout<<(maxtravtime<=k ? "DA" : "NE")<<endl;
    return 0;
}

Compilation message

burza.cpp: In function 'void dfs(long long int)':
burza.cpp:14:10: warning: unused variable 'j' [-Wunused-variable]
   14 |     ll i,j;
      |          ^
burza.cpp: In function 'void dfs2(long long int)':
burza.cpp:30:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(i=0;i<son[x].size();i++){
      |             ~^~~~~~~~~~~~~~
burza.cpp:27:10: warning: unused variable 'j' [-Wunused-variable]
   27 |     ll i,j;
      |          ^
burza.cpp: In function 'int main()':
burza.cpp:47:10: warning: unused variable 'j' [-Wunused-variable]
   47 |     ll i,j;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -