Submission #83121

#TimeUsernameProblemLanguageResultExecution timeMemory
83121luciocfBirokracija (COCI18_birokracija)C++14
100 / 100
222 ms34432 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+10; typedef long long ll; int n; ll ans[MAXN], size[MAXN]; vector<int> grafo[MAXN]; void get_size(int u, int p) { for (int i = 0; i < grafo[u].size(); i++) { int v = grafo[u][i]; if (v == p) continue; get_size(v, u); size[u] += size[v]; } size[u]++; } void DFS(int u, int p) { for (int i = 0; i < grafo[u].size(); i++) { int v = grafo[u][i]; if (v == p) continue; DFS(v, u); ans[u] += (size[v]+ans[v]); } ans[u]++; } int main(void) { cin >> n; for (int i = 2; i <= n; i++) { int x; cin >> x; grafo[x].push_back(i); grafo[i].push_back(x); } get_size(1, -1); DFS(1, -1); cout << ans[1]; for (int i = 2; i <= n; i++) cout << " " << ans[i]; cout << "\n"; }

Compilation message (stderr)

birokracija.cpp: In function 'void get_size(int, int)':
birokracija.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < grafo[u].size(); i++)
                     ~~^~~~~~~~~~~~~~~~~
birokracija.cpp: In function 'void DFS(int, int)':
birokracija.cpp:27:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < grafo[u].size(); i++)
                     ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...