답안 #168312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168312 2019-12-12T11:21:59 Z aydinenes Birokracija (COCI18_birokracija) C++11
70 / 100
227 ms 20052 KB
#include<bits/stdc++.h>

#define mid(l,r) ((l+r)/2)

using namespace std;

const int N = 2e5+7;
const int inf=1e9+7;

int n;

int a[N];

vector<int> g[N];

int ans[N];

void dfsa(int node, int p){
	ans[node] = 1;
	
	for(int i = 0; i < g[node].size(); i++){
		int x = g[node][i];
		if(x == p)	continue;
		dfsa(x, node);
		ans[node] += ans[x];
	}
}

void dfsb(int node, int p){
	for(int i = 0; i < g[node].size(); i++){
		int x = g[node][i];
		if(x == p)	continue;
		dfsb(x, node);
		ans[node] += ans[x];
	}
}

int main(){
	
	cin >> n;
	
	for(int i = 2; i <= n; i++){
		cin >> a[i];
		g[i].push_back(a[i]);
		g[a[i]].push_back(i);
	}
	
	dfsa(1, 0);
	dfsb(1, 0);
	
	for(int i=1; i <= n; i++){
		cout << ans[i] << " ";
	}
}



Compilation message

birokracija.cpp: In function 'void dfsa(int, int)':
birokracija.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[node].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
birokracija.cpp: In function 'void dfsb(int, int)':
birokracija.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[node].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 8 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5880 KB Output is correct
2 Correct 29 ms 6264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 8028 KB Output is correct
2 Correct 66 ms 8056 KB Output is correct
3 Correct 64 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 13984 KB Output is correct
2 Incorrect 176 ms 16528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 13868 KB Output is correct
2 Correct 188 ms 15424 KB Output is correct
3 Incorrect 179 ms 17784 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 13688 KB Output is correct
2 Correct 179 ms 15652 KB Output is correct
3 Incorrect 175 ms 20052 KB Output isn't correct