L2-040 哲哲打游戏

题目 L2-040 哲哲打游戏

image-cde4fe6d

思路分析

image-c62e28cd

代码实现

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

using ll = long long;

using ull = unsigned long long;

using PII = pair<int, int>;

using Pll = pair<ll, ll>;

int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };

const int inf = 0x3f3f3f3f;

signed main() {

    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n,m;cin>>n>>m;

    vector<vector<int>> g(n+1);

    vector<int> cundang(n+1);

    for(int i=1;i<=n;i++){

    	int k;cin>>k;

    	g[i].push_back(i);//0号位置填充掉

    	while(k--){

    		int to;cin>>to;

			g[i].push_back(to);

		}

	}

    int cur=1;

    for(int i=1;i<=m;i++){

    	int op,val;cin>>op>>val;

    	if(op==1){

    		cundang[val]=cur;

    		cout<<cur<<endl;

		}

		else if(op==0){

			cur=g[cur][val];

		}

		else if(op==2){

			cur=cundang[val];

		}

	}

    cout<<cur<<endl;

    return 0;

}

同类题型

视频讲解


⬅️ L2-039 清点代码库 🏠 00-天梯赛 ➡️ L2-041 插松枝