제출 #550441

#제출 시각아이디문제언어결과실행 시간메모리
550441Jarif_RahmanCat in a tree (BOI17_catinatree)C++17
100 / 100
72 ms23404 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n, D;
vector<vector<int>> v;
vector<pair<int, int>> dp;

void dfs(int nd){
    for(int x: v[nd]) dfs(x);
    int d = 1e9, s = 0;
    vector<int> sth;
    for(int x: v[nd]) s+=dp[x].f, sth.pb(dp[x].sc+1);
    sort(sth.begin(), sth.end());
    if(!sth.empty()) d = sth[0];
    for(int i = 1; i < sth.size(); i++) if(sth[i]+sth[i-1] < D) s--, d = sth[i];

    dp[nd].f = s;
    if(d >= D) dp[nd].f++, dp[nd].sc = 0;
    else dp[nd].sc = d;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> D;
    v.resize(n);
    dp.resize(n);
    for(int i = 1; i < n; i++){
        int p; cin >> p;
        v[p].pb(i);
    }

    dfs(0);

    cout << dp[0].f << "\n";
}

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp: In function 'void dfs(int)':
catinatree.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 1; i < sth.size(); i++) if(sth[i]+sth[i-1] < D) s--, d = sth[i];
      |                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...