답안 #81661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81661 2018-10-26T04:08:52 Z luckyboy Birokracija (COCI18_birokracija) C++14
100 / 100
96 ms 28184 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 200005
#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 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5324 KB Output is correct
2 Correct 6 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5324 KB Output is correct
2 Correct 7 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5324 KB Output is correct
2 Correct 6 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5756 KB Output is correct
2 Correct 12 ms 6120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 7196 KB Output is correct
2 Correct 23 ms 7452 KB Output is correct
3 Correct 36 ms 8520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 11696 KB Output is correct
2 Correct 58 ms 15248 KB Output is correct
3 Correct 96 ms 28184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 28184 KB Output is correct
2 Correct 63 ms 28184 KB Output is correct
3 Correct 65 ms 28184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 28184 KB Output is correct
2 Correct 60 ms 28184 KB Output is correct
3 Correct 67 ms 28184 KB Output is correct