求助
查看原帖
求助
158400
晴空一鹤楼主2020/7/28 11:32

请问各位大佬为什么只有测试数据一过了?

#include<bits/stdc++.h>
using namespace std;
long long int ans=0;long long int t[555555];
char s[555555];
vector<int>e[555555];
int inline dfs(int x,int y,int k,int f)
{
	if(y!=0&&s[k]!='(')
	t[k]=t[x]+1+t[f];
	if(s[k]=='(')
	t[k]=t[y];
	for(int o=0;o<e[k].size();o++)
	{
		int ll=x,gg=y;
		if(s[e[k][o]]==')')
		y=e[k][o];
		if(s[e[k][o]]=='(')
		x=y;
		dfs(x,y,e[k][o],k);
		x=ll;
		y=gg;
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>s[i];
	for(int j=2;j<=n;j++)
	{
	int l;
	cin>>l;
	e[l].push_back(j);
	}
	dfs(0,0,1,0);
	for(int i=1;i<=n;i++)
	{
		
	ans=ans^i*t[i];
	}
	cout<<ans<<endl;
	return 0;
}
2020/7/28 11:32
加载中...