# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42856 | 2018-03-05T15:16:54 Z | iletavcioski | Birokracija (COCI18_birokracija) | C++14 | 101 ms | 28864 KB |
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> using namespace std; typedef long long ll; vector<vector<int> > v; ll dp[200002]; ll dp_1[200002]; void dfs(int x) { ll brojac=1; for(int i=0;i<v[x].size();i++) { dfs(v[x][i]); dp_1[x]+=dp_1[v[x][i]]; dp[x]+=dp[v[x][i]]; } dp_1[x]++; dp[x]+=dp_1[x]; } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin>>n; vector<int> vec; v.insert(v.begin(),n+1,vec); for(int i=1;i<n;i++) { int a; cin>>a; a--; v[a].push_back(i); } for(int i=0;i<n;i++) sort(v[i].begin(),v[i].end()); dfs(0); for(int i=0;i<n;i++) { if(i) cout<<" "; cout<<dp[i]; } cout<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 464 KB | Output is correct |
2 | Correct | 2 ms | 596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Output is correct |
2 | Correct | 2 ms | 652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 652 KB | Output is correct |
2 | Correct | 2 ms | 764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1928 KB | Output is correct |
2 | Correct | 10 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 5444 KB | Output is correct |
2 | Correct | 25 ms | 6076 KB | Output is correct |
3 | Correct | 26 ms | 7300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 14784 KB | Output is correct |
2 | Correct | 77 ms | 17952 KB | Output is correct |
3 | Correct | 82 ms | 28044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 28044 KB | Output is correct |
2 | Correct | 77 ms | 28044 KB | Output is correct |
3 | Correct | 72 ms | 28044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 28044 KB | Output is correct |
2 | Correct | 73 ms | 28044 KB | Output is correct |
3 | Correct | 69 ms | 28864 KB | Output is correct |