# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541247 | 2022-03-22T20:20:26 Z | Ahmad_Hasan | Birokracija (COCI18_birokracija) | C++17 | 1000 ms | 13412 KB |
#include <bits/stdc++.h> using namespace std; vector<vector<int>>adj ; int n; vector<int>can; vector<int>ans; int o=0; int dfs(int m=0,int p=-1){ /** if(vis[m]==1||can[m]==1){ return 0; }*/ /**if(adj[m].size()==1&&m!=0){///leaf node can[m]=1; return 1; }*/ int mn=1e6; for(int i=0;i<adj[m].size();i++){ int nd=adj[m][i]; if(nd!=p&&!can[nd]){ mn=nd; break; } } if(mn==1e6){ can[m]=1; ans[m]+=1; return 1; } int ret=dfs(mn,m); ret++; ans[m]+=ret; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; adj=vector<vector<int> >(n); can=ans=vector<int>(n); for(int i=2;i<=n;i++){ int u; cin>>u; adj[u-1].push_back(i-1); adj[i-1].push_back(u-1); } for(int i=0;i<n;i++){ dfs(); } for(int i=0;i<n;i++){ cout<<ans[i]<<' '; } cout<<'\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 2 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1620 KB | Output is correct |
2 | Correct | 629 ms | 1908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 4948 KB | Output is correct |
2 | Execution timed out | 1086 ms | 4844 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 13380 KB | Output is correct |
2 | Execution timed out | 1099 ms | 13064 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 123 ms | 13412 KB | Output is correct |
2 | Execution timed out | 1094 ms | 13044 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 126 ms | 13136 KB | Output is correct |
2 | Execution timed out | 1090 ms | 12840 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |