108022024-04-14 11:48:20AblablablaVállalati ügyeletcpp17Accepted 100/100587ms155764 KiB
#include <bits/stdc++.h>

using namespace std;

vector<int> ans;
vector<set<int>> lefed;
vector<vector<int>> csucsok;
vector<int> vallal;

void dfs(int akt, int elozo){
    int maxi = 1;
    lefed[akt].insert(vallal[akt]);
    for(int x : csucsok[akt]){
        assert(x != elozo);

        dfs(x, akt);
        maxi = max(maxi, ans[x]);

        if(lefed[akt].size() < lefed[x].size()){
            swap(lefed[akt], lefed[x]);
        }

        for(int y : lefed[x]){
            lefed[akt].insert(y);
        }
    }

    while(lefed[akt].count(maxi) > 0){
        maxi++;
    }

    ans[akt] = maxi;
}

int main()
{
    int n;
    cin >> n;

    vector<int> szulo(n);
    for(int &x : szulo){
        cin >> x;
        x--;
    }

    csucsok.assign(n, vector<int>());
    for(int i = 1; i < n; i++){
        csucsok[szulo[i]].push_back(i);
    }

    vallal.assign(n, 0);
    for(int &x : vallal){
        cin >> x;
    }

    ans.assign(n, 1);
    lefed.assign(n, set<int>());

    dfs(0, -1);

    for(int x : ans){
        cout << x << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted314ms99064 KiB
subtask25/5
3Accepted3ms2384 KiB
4Accepted3ms2480 KiB
5Accepted3ms2636 KiB
6Accepted3ms2872 KiB
subtask38/8
7Accepted3ms2384 KiB
8Accepted3ms2480 KiB
9Accepted3ms2636 KiB
10Accepted3ms2872 KiB
11Accepted184ms57120 KiB
12Accepted194ms58148 KiB
13Accepted211ms58972 KiB
14Accepted303ms75348 KiB
subtask412/12
15Accepted3ms2384 KiB
16Accepted3ms2480 KiB
17Accepted3ms2636 KiB
18Accepted3ms2872 KiB
19Accepted256ms112236 KiB
20Accepted263ms113232 KiB
21Accepted270ms114344 KiB
22Accepted358ms130256 KiB
23Accepted326ms130428 KiB
24Accepted284ms121040 KiB
subtask517/17
25Accepted3ms2384 KiB
26Accepted3ms2480 KiB
27Accepted3ms2636 KiB
28Accepted3ms2872 KiB
29Accepted4ms4520 KiB
30Accepted4ms5044 KiB
31Accepted4ms5040 KiB
32Accepted6ms5064 KiB
33Accepted6ms5084 KiB
34Accepted4ms4648 KiB
35Accepted6ms5420 KiB
36Accepted4ms5104 KiB
37Accepted6ms5356 KiB
38Accepted6ms5340 KiB
39Accepted4ms5260 KiB
40Accepted6ms5396 KiB
41Accepted4ms5640 KiB
subtask628/28
42Accepted409ms120712 KiB
43Accepted367ms109276 KiB
44Accepted337ms109512 KiB
45Accepted335ms115488 KiB
46Accepted338ms122412 KiB
47Accepted314ms128352 KiB
48Accepted324ms77076 KiB
49Accepted356ms131460 KiB
50Accepted326ms131592 KiB
subtask730/30
51Accepted3ms5056 KiB
52Accepted314ms101840 KiB
53Accepted3ms2384 KiB
54Accepted3ms2480 KiB
55Accepted3ms2636 KiB
56Accepted3ms2872 KiB
57Accepted184ms57120 KiB
58Accepted194ms58148 KiB
59Accepted211ms58972 KiB
60Accepted303ms75348 KiB
61Accepted256ms112236 KiB
62Accepted263ms113232 KiB
63Accepted270ms114344 KiB
64Accepted358ms130256 KiB
65Accepted326ms130428 KiB
66Accepted284ms121040 KiB
67Accepted4ms4520 KiB
68Accepted4ms5044 KiB
69Accepted4ms5040 KiB
70Accepted6ms5064 KiB
71Accepted6ms5084 KiB
72Accepted4ms4648 KiB
73Accepted6ms5420 KiB
74Accepted4ms5104 KiB
75Accepted6ms5356 KiB
76Accepted6ms5340 KiB
77Accepted4ms5260 KiB
78Accepted6ms5396 KiB
79Accepted4ms5640 KiB
80Accepted409ms120712 KiB
81Accepted367ms109276 KiB
82Accepted337ms109512 KiB
83Accepted335ms115488 KiB
84Accepted338ms122412 KiB
85Accepted314ms128352 KiB
86Accepted324ms77076 KiB
87Accepted356ms131460 KiB
88Accepted326ms131592 KiB
89Accepted365ms96632 KiB
90Accepted361ms103472 KiB
91Accepted587ms143808 KiB
92Accepted546ms155764 KiB
93Accepted314ms102608 KiB
94Accepted365ms114800 KiB
95Accepted349ms127332 KiB
96Accepted331ms98836 KiB
97Accepted293ms98340 KiB
98Accepted296ms99724 KiB
99Accepted342ms107816 KiB
100Accepted321ms101844 KiB
101Accepted305ms107548 KiB