比赛 2025暑假集训第一场 评测结果 WWWWTTTTTT
题目名称 Game of Stack 最终得分 0
用户昵称 二乾五 运行时间 12.155 s
代码语言 C++ 内存使用 14.40 MiB
提交时间 2025-06-25 09:35:47
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define cl(a) memset(a,0,sizeof a)
#define copy(a,b) copy(begin(a),end(a),begin(b))
#define ld long double
#define dot(x) fixed<<setprecision(x)
#define foru(a,b,c) for(ll a=b;a<=c;a++)

ll n,stat[100050];
vector<vector<ll>>a(100050);

int main(){
    freopen("stack.in","r",stdin);
    freopen("stack.out","w",stdout);
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        a[i].push_back(x);
        for(ll j=1;j<=a[i][0];j++){
            cin>>x;
            a[i].push_back(x);
        }
    }
    for(ll i=1;i<=n;i++){
        for(ll jj=1;jj<=n;jj++){
            stat[jj]=1;
        }
        pair<ll,ll>now={i,1};
        while(1){
            if(now.second==a[now.first][0]+1){
                break;
            }
            stat[now.first]++;
            ll tmp=a[now.first][now.second];
            now={tmp,stat[tmp]};
        }
        cout<<now.first<<" ";
    }
    return 0;
}