段错误求助
  • 板块学术版
  • 楼主沧桑の天骄
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/3/18 16:41
  • 上次更新2023/10/28 06:19:14
查看原帖
段错误求助
25891
沧桑の天骄楼主2022/3/18 16:41
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#define ll long long
using namespace std;
inline ll max(ll x,ll y){return x>y?x:y;}
inline ll min(ll x,ll y){return x<y?x:y;}
inline void swap(ll &x,ll &y){x^=y^=x^=y;}
inline ll read(){
	ll x=0,w=1;
	char aa=getchar();
	while(aa<'0'||aa>'9'){
		if(aa=='-') w=-1;
		aa=getchar();
	}
	while(aa>='0'&&aa<='9'){
		x=(x<<3)+(x<<1)+aa-'0';
		aa=getchar();
	}
	return x*w;
}
const int N=1e7+10;

int n;
int fa[N],dep[N],h[N],son[N];
vector<ll> e[N];

void dfs(int u) {
	for(int i=0;i<e[u].size();i++) {
		int v=e[u][i];
		dep[v]=dep[u]+1,dfs(v);
		if(h[v]>h[son[u]]) son[u]=v;
	}
	h[u]=h[son[u]]+1;
}

int main(){
	freopen("tourist.in","r",stdin);
	freopen("tourist.out","w",stdout);
	n=read();
	for(int i=2;i<=n;i++) e[fa[i]=read()].push_back(i);
	dfs(1);
	return 0;
}

输入500000,然后再从1一直输入到499999。

一直显示段错误,有哪位大佬知道原因吗???

2022/3/18 16:41
加载中...