很简单的一道题,但是看不懂题目意思卡了很久。其实就是邻接表存下各个剧情点之间的关系后,操作0就是前往当前剧情点能去的第j条路.
#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
int n, m;
int cd[N];
int res = 1;
vector<int> e[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int num;
cin >> num;
while (num--)
{
int id;
cin >> id;
e[i].push_back(id);
}
}
while (m--)
{
int op, j;
cin >> op >> j;
if (op == 0)
res = e[res][j - 1];
else if (op == 1)
{
cd[j] = res;
cout << res << endl;
}
else
res = cd[j];
}
cout << res << endl;
}
|