QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199813 | #7347. HDRF | Delay_for_five_minutes# | WA | 1ms | 8316kb | C++14 | 1.7kb | 2023-10-04 14:09:50 | 2023-10-04 14:09:50 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 100005
#define MXVAL 1000000000
int mn[maxn << 2];
int r[maxn];
int dfn[maxn],sz[maxn],cnt,idx[maxn];
int min(int u, int v) {
if (u == 0 || v == 0) return v + u;
return r[u] > r[v] ? v : u;
}
void build(int pos,int l,int r) {
if (l == r) {
mn[pos] = idx[l];
return ;
}
int mid = (l+r) >> 1;
build(pos << 1, l, mid);
build(pos << 1 | 1, mid + 1, r);
mn[pos] = min(mn[pos << 1], mn[pos << 1 | 1]);
}
int query(int pos,int l,int r,int ql,int qr) {
if (r < ql || l > qr) return 0;
if (ql <= l && r <= qr) {
return mn[pos];
}
int mid = (l+r) >> 1;
return min(query(pos << 1, l, mid, ql, qr),query(pos << 1 | 1, mid + 1, r, ql, qr));
}
void update(int pos,int l,int r,int p) {
if (l == r) return ;
int mid = (l+r) >> 1;
if (p <= mid) update(pos << 1, l, mid, p);
else update(pos << 1 | 1,mid + 1, r, p);
mn[pos] = min(mn[pos << 1], mn[pos << 1 | 1]);
}
int n;
std::vector<int> G[maxn];
std::vector<int> ans;
void DFS(int u) {
dfn[u] = ++cnt;
sz[u] = 1;
idx[cnt] = u;
for(auto i : G[u]) {
DFS(i);
sz[u] += sz[i];
}
}
void dfs(int u) {
r[u] = 1e9 + 1;
update(1, 1, n, u);
for(int val = query(1, 1, n, dfn[u],dfn[u] + sz[u] - 1); r[val] <= MXVAL;) {
dfs(val);
val = query(1, 1, n, dfn[u],dfn[u] + sz[u] - 1);
}
ans.push_back(u);
}
int main() {
std::ios::sync_with_stdio(0);std::cin.tie(0);
// freopen("in.txt","r",stdin);
std::cin >> n;
for(int i = 2; i <= n; i++) {
int x;
std::cin >> x;
G[x].push_back(i);
}
for(int i=1;i<=n;i++) {
std::cin >> r[i];
}
DFS(1);
// for(int i = 1;i<=n;i++) {
// printf("%d\n",dfn[i]);
// }
build(1,1,n);
dfs(1);
for(auto i:ans) {
printf("%d ", i);
}
putchar('\n');
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 8316kb
input:
5 4 4 1 1 3 5 2 1 4
output:
3 2 4 1
result:
wrong answer 4th numbers differ - expected: '5', found: '1'