QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740892 | #5455. TreeScript | ucup-team2179 | WA | 14ms | 3608kb | C++23 | 2.0kb | 2024-11-13 12:09:38 | 2024-11-13 12:09:38 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pb push_back
bool debug=1;
#define dbg(x) if(debug)cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
using namespace std;void ass(string err){cout<<err<<"\n";exit(0);}void ass(int err){cout<<err<<"\n";exit(0);}
typedef pair<int,int> pii;
const string COLOR_RESET = "\033[0m", BRIGHT_CYAN = "\033[1;36m", NORMAL_FAINT = "\033[0;2m";
vector<int> a[100005 + 1];
int dfs(int u){
vector<int> now;
for(auto p:a[u]){
now.pb(dfs(p));
}
sort(now.begin(), now.end());
if(now.size()==0)
return 1;
if(now.size()==1)
return now[0];
return max(now[0],now[1] + 1);
}
void solve()
{
ios::sync_with_stdio(false);cin.tie(0);mt19937_64 engie(202202052100238523);
int n;
cin>>n;
for (int i = 0; i <= n;i++)
a[i].clear();
for (int i = 1; i <= n;i++){
int u;
cin>>u;
a[u].pb(i);
}
cout<<dfs(1);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;
cin>>t;
while(t--)
{
solve();
cout << "\n";
}
return 0;
}
//__builtin_popcountl( ) 计算二进制1个数
//cout<<fixed<<setprecision(2);输出小数,四舍六入五取偶
//__builtin_ctz( )返回末尾0的个数
//__builtin_clz( ) 返回前导0的个数
//__builtin_parity( )返回1的个数的奇偶性,偶数返回0
//__builtin_ffs( )返回最后一个1在第几位
//__builtin_sqrt( )快速开平方
//stoll()字符串转为长整形
//点(x,y)的极角atan2(y,x)
//点(x,y)逆时针旋转A度,(x*cosA-y*sinA , x*sinA+y*cosA )
//C(n,k)+C(n,k-1)=(n+1,k)
//string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多strlen”
//(从stridx开始往后strlen个字符)的部分作为字符串的初值
/*
int fp(int a,int b)
{
int re=1;
while(b)
{
if(b&1)re*=a;
a*=a;re%=M;a%=M;
b=b>>1;
}
return re;
}
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
2 3 0 1 2 7 0 1 2 2 1 4 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 3608kb
input:
1000 197 0 1 1 2 1 4 1 5 8 3 5 1 4 7 12 14 4 7 10 9 12 11 16 10 21 19 22 17 25 13 28 9 5 15 26 26 33 25 15 1 35 6 32 17 37 8 19 43 19 27 29 9 30 6 31 27 35 35 37 13 28 38 57 31 38 8 22 14 33 9 18 62 52 37 10 19 22 60 54 12 38 59 64 65 80 82 28 60 85 78 27 25 71 14 52 6 59 14 87 32 33 41 59 41 88 38 ...
output:
3 3 2 2 2 2 2 3 4 2 2 3 2 3 3 3 3 2 2 3 3 3 2 2 2 2 2 2 3 2 2 3 2 3 3 3 5 3 2 2 2 2 2 2 2 3 2 3 3 2 3 2 2 3 2 2 2 2 3 2 2 3 2 2 2 2 2 3 3 3 2 2 3 2 3 2 2 3 3 1 1 2 3 2 3 2 2 2 2 2 2 2 4 2 3 2 2 3 2 2 2 3 3 3 3 3 2 6 2 2 3 3 2 2 3 4 2 3 3 2 4 3 3 2 3 3 3 3 3 2 2 2 3 2 3 3 4 2 2 2 4 2 3 2 2 2 2 3 3 2 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '3'