QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575159 | #9101. Zayin and Bus | leafmaple# | AC ✓ | 153ms | 15560kb | C++20 | 978b | 2024-09-19 10:59:13 | 2024-09-19 10:59:17 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,db> pdd;
const int mod = 1e9 + 7;
const int inf = 1800000000000000000;
const int N = 1000005;
int n;
int a[N],f[N];
vector<int>v[N];
void dfs(int x,int fa){
f[x] = f[fa] + 1;
for(auto i:v[x]){
if(i!=fa){
dfs(i,x);
}
}
}
void solve(){
int n;cin>>n;
for(int i=1;i<=n;i++){
v[i].clear();
}
for(int i=1;i<n;i++){
int x;cin>>x;
int y=i+1;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=i;
}
f[0]=-1;
dfs(1,0);
sort(a+1,a+1+n);
sort(f+1,f+1+n,greater<int>());
int mi=a[1]+f[1];
for(int i=1;i<=n;i++){
// cout<<f[i]<<' '<<a[i]<<endl;
mi=max(mi,f[i]+a[i]);
}
cout<<mi<<endl;
}
signed main(){
IOS
int T;cin>>T;
while(T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7832kb
input:
14 1 1 1 2 1 3 2 1 1 1 2 1 1 2 2 1 2 1 2 1 1 3 2 1 3 1 2 1 1 4 2 1 4 1 3 1 1 1 1 1 3 1 2 1 1 1 3 1 1 1 3 2 3 1 2 1 3 2
output:
2 3 4 3 4 4 5 4 6 5 4 4 6 6
result:
ok 14 lines
Test #2:
score: 0
Accepted
time: 153ms
memory: 15560kb
input:
15 1000 1 2 2 1 1 1 4 8 1 7 7 7 9 3 4 7 15 18 18 4 6 11 19 7 6 1 9 13 2 21 28 6 17 24 24 2 28 5 32 24 23 8 3 26 15 28 25 34 46 41 33 16 46 11 7 2 13 53 12 59 52 53 51 52 31 41 63 18 55 49 55 62 15 19 23 67 18 37 2 4 23 75 58 55 14 84 20 3 7 89 82 15 53 77 60 25 97 69 5 40 54 24 72 10 87 90 99 43 71 ...
output:
98572828 100088663 99870474 100076153 99995412 100076982 99971239 100079684 99928633 100093408 99432584 100093568 99620300 100058966 99565256
result:
ok 15 lines