Submission #300043

#TimeUsernameProblemLanguageResultExecution timeMemory
300043shrek12357Birokracija (COCI18_birokracija)C++14
70 / 100
193 ms17784 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> using namespace std; const int MAXN = 2 * 1e5 + 5; int par[MAXN]; vector<int> adjList[MAXN]; int subtree[MAXN], sums[MAXN]; void dfs(int src) { for (auto i : adjList[src]) { dfs(i); subtree[src] += subtree[i]; sums[src] += subtree[i] + sums[i]; } } int main() { int n; cin >> n; par[1] = 1; subtree[1] = 0; sums[1] = 1; for (int i = 2; i <= n; i++) { int temp; cin >> temp; par[i] = temp; adjList[temp].push_back(i); subtree[i] = 1; sums[i] = 1; } dfs(1); for (int i = 1; i <= n; i++) { cout << sums[i]; if (i != n) { cout << " "; } } cout << endl; }
#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...