Submission #3087791
Source Code Expand
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq) (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw) (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe) transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr) transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy) for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu) FOR(i,0,upupu)
# define INIT std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)
int n;
vector<int> G[101010];
int calc[101010];
int par[101010];
int dfs(int cur, int pre) {
int ret = 1;
par[cur] = pre;
REP(i, G[cur].size()) {
if (G[cur][i] != pre) {
ret += dfs(G[cur][i], cur);
}
}
return calc[cur] = ret;
}
int main() {
cin >> n;
REP(i, n - 1) {
int num;
cin >>num;
G[i+1].emplace_back(num);
G[num].emplace_back(i+1);
}
dfs(0, -1);
REP(i, n) {
int ans = n - calc[i];
REP(j, G[i].size()) {
if (G[i][j] != par[i]) {
ans = max(ans, calc[G[i][j]]);
}
}
cout << ans << endl;
}
//system("pause");
}
Submission Info
Submission Time |
|
Task |
C - 高橋王国の分割統治 |
User |
M3_cp |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2132 Byte |
Status |
AC |
Exec Time |
211 ms |
Memory |
14976 KB |
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 |
2 ms |
2560 KB |
sample_02.txt |
AC |
2 ms |
2560 KB |
subtask1_01.txt |
AC |
2 ms |
2560 KB |
subtask1_02.txt |
AC |
2 ms |
2560 KB |
subtask1_03.txt |
AC |
2 ms |
2560 KB |
subtask1_04.txt |
AC |
2 ms |
2560 KB |
subtask1_05.txt |
AC |
4 ms |
2688 KB |
subtask1_06.txt |
AC |
4 ms |
2688 KB |
subtask1_07.txt |
AC |
4 ms |
2688 KB |
subtask1_08.txt |
AC |
4 ms |
2688 KB |
subtask1_09.txt |
AC |
4 ms |
2688 KB |
subtask2_01.txt |
AC |
149 ms |
6016 KB |
subtask2_02.txt |
AC |
185 ms |
6784 KB |
subtask2_03.txt |
AC |
203 ms |
7168 KB |
subtask2_04.txt |
AC |
211 ms |
7168 KB |
subtask2_05.txt |
AC |
178 ms |
7544 KB |
subtask2_06.txt |
AC |
182 ms |
7680 KB |
subtask2_07.txt |
AC |
203 ms |
14976 KB |