静态链表10分求调
  • 板块灌水区
  • 楼主LJFWSB
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/22 18:21
  • 上次更新2025/1/22 21:16:01
查看原帖
静态链表10分求调
1004540
LJFWSB楼主2025/1/22 18:21
#include<bits/stdc++.h>
using namespace std;
struct Node{
 	int data;    
	int nextid; 
}s[1000100];
int main()
{
	s[1].data=1;
	int q,a,x,y;
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>a;
		if(a==1) cin>>x>>y;
		else cin>>x;
		if(a==1)
		{
			s[x].nextid=y;
			s[y].nextid=-1;
		}
		if(a==2)
			cout<<s[x].nextid<<endl;
		if(a==2&&s[x].nextid==-1) cout<<0<<endl;
		if(a==3) 
		{
			s[x].nextid=s[s[x].nextid].nextid;
		}
	}
	return 0;
}

题目传送门:https://www.luogu.com.cn/problem/B3631

2025/1/22 18:21
加载中...