输入样例:
10 11
3 2 3 4
1 6
3 4 7 5
1 3
1 9
2 3 5
3 1 8 5
1 9
2 8 10
0
1 1
0 3
0 1
1 2
0 2
0 2
2 2
0 3
0 1
1 1
0 2
输出样例:
1
3
9
10
直接用二维数组会炸内存,所以用vector的一维数组当二维数组使用。
用vector a[N] 数组来存放每个剧情点对应操作能跳到哪个剧情点。
用int b[N]来存每个存档点对应的剧情点。
然后直接模拟即可。
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#define llu unsigned long long
using namespace std;
vector<int> a[100010];
int b[100010];
int main()
{
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++)
{
int t;
cin >> t ;
a[i].push_back(-1);
for(int j=1;j<=t;j++)
{
int x;
cin >> x;
a[i].push_back(x); ;
}
}
int t=1;//当前的剧情点,初始为1
for(int i=1;i<=m;i++)
{
int k,l;
cin >> k >> l;
if(k==0){
t=a[t][l];
}
if(k==1){
b[l]=t;
cout << t << endl ;
}
if(k==2){
t=b[l];
}
}
cout << t << endl ;
return 0;
}