UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213820#582. t1NCompile Error//C++963b2024-11-13 20:27:232024-11-13 23:06:35

answer

//
//  na 1156.cpp
//  Competitive Programming
//
//  Created by m2 on 2024/11/13.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#ifdef MAC_OS_VERSION_11_0
const int maxn = 15;
#else
const int maxn = 1e5 + 5;
#endif
int n, v[maxn], r[maxn], p[maxn];
vector<int> ch[maxn];
void dfs1(int idx){
    r[idx] = v[idx];
    for(int c: ch[idx]){
        dfs1(c);
        r[idx] = min(r[idx], r[c]);
    }
}
inline bool cmpr(int a, int b){
    return r[a] < r[b];
}
void sol(int idx){
    sort(ch[idx].begin(), ch[idx].end(), cmpr);
    for(int c: ch[idx])
        sol(c);
    cout << idx << ' ';
}
int main(){
    cin.tie(0)->sync_with_stdio(false);
    cin >> n;
    for(int i = 2; i <= n; ++i){
        cin >> p[i];
        ch[p[i]].push_back(i);
    }
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    dfs1(1);
    sol(1);
    cout << endl;
    return 0;
}

详细

answer.code: In function 'void dfs1(int)':
answer.code:22:16: error: range-based 'for' loops are not allowed in C++98 mode
     for(int c: ch[idx]){\x0d
                ^
answer.code: In function 'void sol(int)':
answer.code:32:16: error: range-based 'for' loops are not allowed in C++98 mode
     for(int c: ch[idx])\x0d
                ^