QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#754790#6735. TreeMocic1WA 3ms27080kbC++14907b2024-11-16 15:48:242024-11-16 15:48:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 15:48:24]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:27080kb
  • [2024-11-16 15:48:24]
  • 提交

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'