QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#754790 | #6735. Tree | Mocic1 | WA | 3ms | 27080kb | C++14 | 907b | 2024-11-16 15:48:24 | 2024-11-16 15:48:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
typedef pair<int, int> PII;
const int N = 1000007;
const int inf = 1e18;
const int mod = 1e9+7;
mt19937_64 rng(time(0));
vector<int>v[N];
map<int,int>mp;
int n;
int mx;
void dfs(int u,int d){
mp[d]++;
mx=max(mx,d);
for(auto i:v[u]){
dfs(i,d+1);
}
}
void solve() {
cin>>n;
for(int i=2;i<=n;i++){
int x;
cin>>x;
v[x].pb(i);
}
mx=0;
mp.clear();
dfs(1,1);
int ans=mx;
for(auto [x,y]:mp){
ans=min(ans,y+mx-x);
}
cout<<ans<<'\n';
for(int i=0;i<n+1;i++)v[i].clear();
}
signed main() {
ios;
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 27080kb
input:
5 5 5 4 3 4 5 1 2 3 1 2 2 2 2 4 9 2 6 2 5 4 5 5 4 3 5 2 1
output:
1 1 1 1 1
result:
wrong answer 1st numbers differ - expected: '6', found: '1'