Submission #223836


Source Code Expand

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
struct edge { int u, v; ll w; };

void foo(vector< vector<int> >& ch, vector<int>& a, int i) {
	a[i] = 1;
	for (int j = 0; j < ch[i].size(); j++) {
		int _i = ch[i][j];
		foo(ch, a, _i);
		a[i] += a[_i];
	}
}

int main() {
	int N; cin >> N;
	vector< vector<int> > ch(N);
	for (int i = 1; i < N; i++) {
		int p; scanf("%d", &p);
		ch[p].push_back(i);
	}
	vector<int> a(N);
	foo(ch, a, 0);
	for (int i = 0; i < N; i++) {
		int ans = N - a[i];
		for (int j = 0; j < ch[i].size(); j++) {
			int _i = ch[i][j];
			ans = max(ans, a[_i]);
		}
		printf("%d\n", ans);
	}
}

Submission Info

Submission Time
Task C - 高橋王国の分割統治
User sugim48
Language C++ (G++ 4.6.4)
Score 100
Code Size 1112 Byte
Status AC
Exec Time 97 ms
Memory 13480 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 2
AC × 11
AC × 16
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 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 22 ms 924 KB
sample_02.txt AC 23 ms 924 KB
subtask1_01.txt AC 22 ms 928 KB
subtask1_02.txt AC 22 ms 924 KB
subtask1_03.txt AC 22 ms 800 KB
subtask1_04.txt AC 23 ms 808 KB
subtask1_05.txt AC 21 ms 796 KB
subtask1_06.txt AC 23 ms 800 KB
subtask1_07.txt AC 21 ms 928 KB
subtask1_08.txt AC 23 ms 800 KB
subtask1_09.txt AC 23 ms 808 KB
subtask2_01.txt AC 73 ms 4304 KB
subtask2_02.txt AC 97 ms 5284 KB
subtask2_03.txt AC 97 ms 5672 KB
subtask2_04.txt AC 89 ms 5660 KB
subtask2_05.txt AC 60 ms 4568 KB
subtask2_06.txt AC 61 ms 4900 KB
subtask2_07.txt AC 86 ms 13480 KB