Submission #1692438


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
vector<vector<int>> v;

int dfs(int src){
  if(v[src].size()==0)return 1;
  int MIN=INF;
  int MAX=(-1)*INF;
  rep(i,v[src].size()){
    int m=dfs(v[src][i]);
    MIN=min(MIN,m);
    MAX=max(MAX,m);
  }
  return MIN+MAX+1;
}

int main(){
  int n;
  cin>>n;
  v=vector<vector<int>> (n);

  rep(i,n-1){
    int b;
    cin>>b;
    b--;
    v[b].pb(i+1);
  }
  cout<<dfs(0)<<endl;
  return 0;
}

Submission Info

Submission Time
Task C - 高橋君の給料
User fuu32
Language C++14 (GCC 5.4.1)
Score 100
Code Size 801 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 22
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt, example_3.txt
All example_0.txt, example_1.txt, example_2.txt, example_3.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, special_0.txt, example_0.txt, example_1.txt, example_2.txt, example_3.txt
Case Name Status Exec Time Memory
example_0.txt AC 1 ms 256 KB
example_1.txt AC 1 ms 256 KB
example_2.txt AC 1 ms 256 KB
example_3.txt AC 1 ms 256 KB
maxrand_0.txt AC 1 ms 256 KB
maxrand_1.txt AC 1 ms 256 KB
maxrand_2.txt AC 1 ms 256 KB
random_0.txt AC 1 ms 256 KB
random_1.txt AC 1 ms 256 KB
random_2.txt AC 1 ms 256 KB
random_3.txt AC 1 ms 256 KB
random_4.txt AC 1 ms 256 KB
random_5.txt AC 1 ms 256 KB
random_6.txt AC 1 ms 256 KB
random_7.txt AC 1 ms 256 KB
random_8.txt AC 1 ms 256 KB
random_9.txt AC 1 ms 256 KB
special_0.txt AC 1 ms 256 KB