제출 #1174766

#제출 시각아이디문제언어결과실행 시간메모리
1174766Tien_NoobCat in a tree (BOI17_catinatree)C++20
100 / 100
268 ms243652 KiB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
vector<int> adj[N + 1];
int n, d;
deque<int> dp[N + 1];
void read()
{
    cin >> n >> d;
    for (int i = 1; i < n; ++ i)
    {
        int u;
        cin >> u;
        adj[u].push_back(i);
    }
}
void DFS(int u)
{
    dp[u].push_back(1); //dp[u][0] = 1
    for (int v : adj[u])
    {
        DFS(v);
        dp[v].push_front(dp[v].front());
        if (dp[u].size() < dp[v].size())
        {
            swap(dp[u], dp[v]);
        }
        for (int j = 0; j < dp[v].size(); ++ j)
        {   
            int k = max(j, d - j);
            int t1 = dp[u][j] + (k >= dp[v].size() ? 0 : dp[v][k]);
            int t2 = dp[v][j] + (k >= dp[u].size() ? 0 : dp[u][k]);
            dp[u][j] = max({dp[u][j], t1, t2});
        }
        for (int j = (int)dp[v].size() - 1; j >= 0; -- j)
        {   
            if (j + 1 < dp[u].size())
            {
                dp[u][j] = max(dp[u][j], dp[u][j + 1]);
            }
        }
    }
}
void solve()
{
    DFS(0);
    cout << dp[0][0];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

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

catinatree.cpp: In function 'int main()':
catinatree.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...