답안 #81660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81660 2018-10-26T04:08:19 Z luckyboy Birokracija (COCI18_birokracija) C++14
70 / 100
23 ms 8596 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <int,int>
#define Task "Birokracija"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n;
long long ans[maxn];
vector <int> a[maxn];
void Dfs(int u)
{
    for (int v : a[u])
    {
        Dfs(v);
        ans[u] += ans[v];
    }
}
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    read(n);
    FOR(i,1,n) ans[i] = 1;
    FOR(i,2,n)
    {
        int x;
        read(x);
        a[x].pb(i);
    }
    Dfs(1);
    Dfs(1);
    FOR(i,1,n) write(ans[i]);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 2784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2932 KB Output is correct
2 Correct 4 ms 2932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3068 KB Output is correct
2 Correct 4 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3596 KB Output is correct
2 Correct 9 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 5560 KB Output is correct
2 Correct 20 ms 6212 KB Output is correct
3 Correct 23 ms 7636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 8560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 8560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 8596 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -