比赛 |
2025暑假集训第一场 |
评测结果 |
RRRRRRRRRR |
题目名称 |
Game of Stack |
最终得分 |
0 |
用户昵称 |
LikableP |
运行时间 |
0.048 s |
代码语言 |
C++ |
内存使用 |
5.93 MiB |
提交时间 |
2025-06-25 11:10:39 |
显示代码纯文本
#include <cstdio>
#include <vector>
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
namespace IO {
template <typename T>
T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
template <typename T>
void write(T x, char ed = '\n') {
if (x < 0)
x = -x, putchar('-');
static int sta[sizeof(T) << 2], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while (x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}
} // namespace IO
using namespace IO;
const int MAXN = 1e5 + 10;
int n;
int k[MAXN], cnt[MAXN];
::std::vector<int> sta[MAXN];
int main() {
freopen("stack", "r", stdin);
freopen("stack", "w", stdout);
n = read<int>();
for (int i = 1; i <= n; ++i) {
k[i] = read<int>();
sta[i].resize(k[i] + 1, 0);
for (int j = 1; j <= k[i]; ++j) {
sta[i][j] = read<int>();
}
}
for (int st = 1; st <= n; ++st) {
for (int i = 1; i <= n; ++i) {
cnt[i] = 0;
}
int now = st;
cnt[now]++;
while (cnt[now] != k[now] + 1) {
now = sta[now][k[now] - cnt[now] + 1];
cnt[now]++;
}
write(now, ' ');
}
return 0;
}