# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1044312 |
2024-08-05T08:47:09 Z |
변재우(#11009) |
Team Coding (EGOI24_teamcoding) |
C++17 |
|
4000 ms |
1048576 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=100010;
int N, K, ans, mn, A[Nmax], C[Nmax], D[Nmax];
vector<int> adj[Nmax];
unordered_map<int, int> X[Nmax];
void DFS1(int curr) {
X[A[curr]][D[curr]]++;
for(int next:adj[curr]) D[next]=D[curr]+1, DFS1(next);
}
pair<unordered_map<int, int>, unordered_map<int, unordered_map<int, int>>> DFS(int curr) {
pair<unordered_map<int, int>, unordered_map<int, unordered_map<int, int>>> ret;
ret.first[D[curr]]++, ret.second[A[curr]][D[curr]]++;
for(int next:adj[curr]) {
pair<unordered_map<int, int>, unordered_map<int, unordered_map<int, int>>> tmp=DFS(next);
if(ret.first.size()<tmp.first.size()) swap(ret, tmp);
for(auto k:tmp.first) ret.first[k.first]+=k.second;
for(auto k:tmp.second) for(auto kk:k.second) ret.second[k.first][kk.first]+=kk.second;
}
int sum=0, val=0;
for(auto k:ret.first) sum+=min(X[A[curr]][k.first], k.second);
for(auto k:ret.first) val+=min(X[A[curr]][k.first]-ret.second[A[curr]][k.first], k.second-ret.second[A[curr]][k.first]);
if(ans<sum) ans=sum, mn=val;
if(ans==sum && mn>val) mn=val;
return ret;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>K;
for(int i=1; i<=N; i++) cin>>A[i], C[++A[i]]++;
for(int i=2; i<=N; i++) {
int p; cin>>p; adj[++p].push_back(i);
}
DFS1(1);
DFS(1);
cout<<ans<<" "<<mn;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8624 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
67 ms |
14108 KB |
Output is correct |
9 |
Runtime error |
1853 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
79 ms |
10692 KB |
Output is correct |
5 |
Execution timed out |
4088 ms |
97868 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8792 KB |
Output is correct |
4 |
Correct |
1 ms |
8848 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Runtime error |
1867 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
77 ms |
14180 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
88 ms |
10712 KB |
Output is correct |
11 |
Correct |
2 ms |
9048 KB |
Output is correct |
12 |
Correct |
267 ms |
136196 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
3 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
22 ms |
9952 KB |
Output is correct |
17 |
Correct |
1 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8816 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
1 ms |
8796 KB |
Output is correct |
23 |
Correct |
6 ms |
9560 KB |
Output is correct |
24 |
Correct |
7 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
9308 KB |
Output is correct |
26 |
Correct |
91 ms |
38228 KB |
Output is correct |
27 |
Correct |
111 ms |
63056 KB |
Output is correct |
28 |
Correct |
6 ms |
9560 KB |
Output is correct |
29 |
Correct |
6 ms |
9564 KB |
Output is correct |
30 |
Correct |
70 ms |
52052 KB |
Output is correct |
31 |
Correct |
9 ms |
9052 KB |
Output is correct |
32 |
Correct |
5 ms |
8796 KB |
Output is correct |
33 |
Correct |
22 ms |
14396 KB |
Output is correct |
34 |
Correct |
3 ms |
8792 KB |
Output is correct |
35 |
Correct |
3 ms |
8796 KB |
Output is correct |
36 |
Correct |
2 ms |
8796 KB |
Output is correct |
37 |
Correct |
2 ms |
8796 KB |
Output is correct |
38 |
Correct |
2 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
2 ms |
8792 KB |
Output is correct |
41 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8624 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
67 ms |
14108 KB |
Output is correct |
9 |
Runtime error |
1853 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |