有大佬帮忙看看为什么最后俩个点TLE吗?
查看原帖
有大佬帮忙看看为什么最后俩个点TLE吗?
937199
chengsong楼主2023/3/26 15:48
#include<iostream>
#include<iomanip>
#include<cmath>
#define ll long long
#define MAXSIZE 100010
using namespace std;
ll n,a[MAXSIZE],h,i;
int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	cin>>h;
	i=h;
	cout<<i<<" ";
	while(a[i]!=0){
		cout<<a[i]<<" ";
		i=a[i];
	}
}
2023/3/26 15:48
加载中...