# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
986384 | FIFI_cpp | Birokracija (COCI18_birokracija) | C++17 | 80 ms | 31568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using ll = long long;
#define pb push_back
#define all(a) a.begin(),a.end()
#define int int64_t
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// xcode cant include bits/stdc++.h
using namespace std;
//ifstream fin ("fenceplan.in");
//ofstream fout ("fenceplan.out");
/* /\_/\
* (= ._.)
* / > \>
*/
// encouraging cat
const ll INF = 100000000000000;
const ll mod = 1000000007;
vector<vector<int>> adj;
vector<int> res;
int children(int curr)
{
int s = 0;
int r = 0;
for (auto edge: adj[curr])
{
s += children(edge);
r += res[edge];
}
res[curr] = r + s + 1;
return s + 1;
}
int32_t main() {
int n;
cin >> n;
adj.resize(n);
res.resize(n);
res[0] = 0;
for (int i = 1;i < n;i++)
{
int from;
cin >> from;
from--;
adj[from].pb(i);
res[i] = 0;
}
children(0);
for (int i = 0;i < n;i++)
{
cout << res[i] << " ";
}
cout << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |