QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309379 | #8134. LCA Counting | ucup-team191# | WA | 4ms | 18192kb | C++14 | 999b | 2024-01-20 16:57:20 | 2024-01-20 16:57:21 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#define X first
#define Y second
#define PB push_back
using namespace std;
const int N = 2e5 + 500;
map < int, int > mp[N];
int n;
vector < int > v[N];
void dfs(int x){
if((int)v[x].size() == 0) {
mp[x][0] = 1; return;
}
if((int)v[x].size() == 1) {
dfs(v[x][0]); swap(mp[x], mp[v[x][0]]);
return;
}
for(int y : v[x]) {
dfs(y);
if((int)mp[y].size() > (int)mp[x].size())
swap(mp[x], mp[y]);
for(auto tmp : mp[y]) mp[x][tmp.X] += tmp.Y;
}
mp[x][0] -= (int)v[x].size() - 2;
mp[x][1] += (int)v[x].size() - 2;
}
int main(){
scanf("%d", &n);
for(int i = 2;i <= n;i++) {
int p; scanf("%d", &p);
v[p].PB(i);
}
dfs(1);
vector < int > ans;
for(auto tmp : mp[1]) {
int t = tmp.Y;
for(;t--;) ans.PB(tmp.X);
}
int sol = 0;
for(int i = 0;i < (int)ans.size();i++) {
sol += ans[i];
printf("%d ", 2 * i + 1 - sol);
}
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17908kb
input:
7 1 1 2 4 2 2
output:
1 3 5 6
result:
ok 4 number(s): "1 3 5 6"
Test #2:
score: 0
Accepted
time: 4ms
memory: 17900kb
input:
10 1 1 2 2 1 1 1 2 4
output:
1 3 5 6 7 8 9
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 18192kb
input:
10 1 2 2 4 5 6 1 2 4
output:
1 3 5 7 8
result:
ok 5 number(s): "1 3 5 7 8"
Test #4:
score: 0
Accepted
time: 0ms
memory: 17908kb
input:
10 1 2 3 3 3 5 6 4 9
output:
1 3 4
result:
ok 3 number(s): "1 3 4"
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 17960kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 4 1 2 2 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 6 3 1 1 1 2 2 1 1 2 1 2 1 3 1 2 1 1 2 1 1 1 1 1 1 1 4 1 5 1 1 1 1 1 2 1 1 2 1 2 1 2 5 3 1 3 1 1 2 1 2 1 1 3 2 1 6 2 1 2 5 1 1 1 3 2 1 2 1 1 1 1 1...
output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 12...
result:
wrong answer 5th numbers differ - expected: '8', found: '9'