比赛 2025暑假集训第一场 评测结果 AAAATTTTTT
题目名称 Game of Stack 最终得分 40
用户昵称 淮淮清子 运行时间 13.316 s
代码语言 C++ 内存使用 46.92 MiB
提交时间 2025-06-25 10:40:59
显示代码纯文本
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

const int MAXN = 1e5 + 5;
int n,k;
int ans[MAXN];

int main(){
	freopen("stack.in","r",stdin);
	freopen("stack.out","w",stdout);
	cin.tie(0) -> ios::sync_with_stdio(0);
    cin >> n;
    vector<vector<int> > a(n + 1);
    for(int i = 1;i <= n;i ++){
        cin >> k;
        a[i].resize(k);
        for(int j = 0;j < k;j ++){
            cin >> a[i][j];
        }
    }
    for(int x = 1;x <= n;x ++){
        vector<stack<int> > s(n + 1);
        for(int i = 1;i <= n;i ++){
            for(int num : a[i]){
                s[i].push(num);
            }
        }
        int cnt = x;
        while(true){
            if(s[cnt].empty()){
                ans[x] = cnt;
                break;
            }
            int nt = s[cnt].top();
            s[cnt].pop();
            cnt = nt;
        }
    }
    for(int i = 1;i <= n;i ++){
        cout << ans[i] << ' ';
    }
	return 0;
}