제출 #1254905

#제출 시각아이디문제언어결과실행 시간메모리
12549053m17Cat in a tree (BOI17_catinatree)C++20
0 / 100
355 ms589824 KiB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define int long long

const int Nmax = 6e5 + 7;
const int LogN = 18;

int n , D;
int Ans;
int dist[Nmax] , a[Nmax] , par[Nmax][18] , parMain[Nmax][18];
bool N_leaf[Nmax];

vector <int> graph[Nmax] , Main_graph[Nmax];

void DFS (int u)
{
    for (int v : graph[u])
    if(v != par[u][0])
    {
        par[u][0] = v;
        dist[v] = dist[u] + 1;
        DFS(v);
    }

    for (int v : graph[u])
    if(v != par[u][0]) N_leaf[u] = true;
}

void DFS_cnt (int u)
{
    Ans++;
    for (int v : Main_graph[u])
    if(v != parMain[u][0])
    {
        parMain[u][0] = v;
        DFS_cnt(v);
    }
}


void Binary_lifting()
{
    for (int i = LogN ; i >= 0 ; i--)
        for (int u = 1 ; u <= n ; u++)
        par[u][i] = par[par[u][i - 1]][i - 1];
}

int Move (int u , int x)
{
    for (int i = LogN ; i >= 0 ; i--)
    if(x & (1 << i)) u = par[u][i];
    return u;
}

main(){
    cin >> n >> D;
    for (int i = 1 ;  i < n ; i++)
    {
        int x;
        cin >> x;
        graph[i].push_back(x);
        graph[x].push_back(i);
    }

    DFS(0);
    for (int i = 1 ; i < n ; i++)
    if(!N_leaf[i])
    {
        if(D > dist[i]) continue;
        int s = Move(i , dist[i] % D);
        while(s != 0)
        {
            int v = Move(s , D);
            Main_graph[s].push_back(v);
            Main_graph[v].push_back(s);
            s = v;
        }
    }

    DFS_cnt(0);
    cout << Ans;
}

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

catinatree.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...