답안 #127393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127393 2019-07-09T10:13:28 Z impri Birokracija (COCI18_birokracija) C++14
100 / 100
255 ms 27000 KB
#include<bits/stdc++.h>
using namespace std;
int number;
vector<int>graph[200001];
int visited[200001];
int siz[200001];
long long money[200001];
int get_size(int n){
  visited[n]=1;
  int result=1;
  for(int i=0;i<graph[n].size();i++){
    if(!visited[graph[n][i]]){
        result+=get_size(graph[n][i]);
    }
  }
  return siz[n]=result;



}
long long get_m(int n){
  long long result=1;
    visited[n]=1;
    for(int i=0;i<graph[n].size();i++){
            if(!visited[graph[n][i]]){
                result+=(get_m(graph[n][i])+siz[graph[n][i]]);
            }

    }
    return money[n]=result;
}
int main() {
 cin >> number;
 for(int i=2;i<=number;i++){
    int a;
    cin >> a;
    graph[i].push_back(a);
    graph[a].push_back(i);
 }
 get_size(1);
 memset(visited,0,sizeof(visited));
 get_m(1);
 for(int i=1;i<=number;i++){
    cout << money[i] << " ";
 }

}

Compilation message

birokracija.cpp: In function 'int get_size(int)':
birokracija.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<graph[n].size();i++){
               ~^~~~~~~~~~~~~~~~
birokracija.cpp: In function 'long long int get_m(int)':
birokracija.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<graph[n].size();i++){
                 ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5800 KB Output is correct
2 Correct 7 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5860 KB Output is correct
2 Correct 7 ms 5756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5752 KB Output is correct
2 Correct 7 ms 5884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 6776 KB Output is correct
2 Correct 26 ms 7160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 9512 KB Output is correct
2 Correct 64 ms 9436 KB Output is correct
3 Correct 65 ms 10460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 16164 KB Output is correct
2 Correct 179 ms 17668 KB Output is correct
3 Correct 181 ms 27000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 16240 KB Output is correct
2 Correct 184 ms 16756 KB Output is correct
3 Correct 175 ms 18552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 16220 KB Output is correct
2 Correct 181 ms 16992 KB Output is correct
3 Correct 175 ms 20348 KB Output is correct