Submission #1151934
Source Code Expand
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> P;
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;
int n;
vector<int> g[112345];
int ans[112345];
int dfs(int pos, int pre) {
vector<int> v;
REP(i, g[pos].size()) if (g[pos][i] != pre)
v.push_back(dfs(g[pos][i], pos));
REP(i, v.size()) chmax(ans[pos], v[i]);
int sum = 1;
REP(i, v.size()) sum += v[i];
chmax(ans[pos], n - sum);
return sum;
}
int main() {
cin >> n;
REP(i, n - 1) {
int p;
scanf("%d", &p);
g[i + 1].push_back(p);
g[p].push_back(i + 1);
}
dfs(0, -1);
REP(i, n) printf("%d\n", ans[i]);
return 0;
}
Submission Info
Submission Time
2017-03-09 10:00:36+0900
Task
C - 高橋王国の分割統治
User
tkmst201
Language
C++ (GCC 5.4.1)
Score
100
Code Size
1409 Byte
Status
AC
Exec Time
51 ms
Memory
16384 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:61:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &p);
^
Judge Result
Set Name
Sample
Subtask1
Subtask2
Score / Max Score
0 / 0
30 / 30
70 / 70
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
Subtask1
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
Subtask2
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt
Case Name
Status
Exec Time
Memory
sample_01.txt
AC
3 ms
2944 KB
sample_02.txt
AC
3 ms
2944 KB
subtask1_01.txt
AC
3 ms
2944 KB
subtask1_02.txt
AC
3 ms
2944 KB
subtask1_03.txt
AC
3 ms
2944 KB
subtask1_04.txt
AC
3 ms
2944 KB
subtask1_05.txt
AC
3 ms
2944 KB
subtask1_06.txt
AC
3 ms
2944 KB
subtask1_07.txt
AC
3 ms
2944 KB
subtask1_08.txt
AC
3 ms
2944 KB
subtask1_09.txt
AC
3 ms
3072 KB
subtask2_01.txt
AC
33 ms
6016 KB
subtask2_02.txt
AC
42 ms
6784 KB
subtask2_03.txt
AC
51 ms
7040 KB
subtask2_04.txt
AC
44 ms
7040 KB
subtask2_05.txt
AC
28 ms
7536 KB
subtask2_06.txt
AC
29 ms
7688 KB
subtask2_07.txt
AC
43 ms
16384 KB