分析:模拟题,关键就是要理解题目意思.m≥3的轮换可以拆成m=2的小轮换,小轮换的话只需要交换一下就可以了.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>using namespace std;int n, p, k, f[][], a[], pos[];int main()
{
scanf("%d%d%d", &n, &p, &k);
for (int i = ; i <= n; i++)
a[i] = i, pos[i] = i;
for (int i = p; i >= ; i--)
{
scanf("%d", &f[i][]);
for (int j = ; j <= f[i][]; j++)
scanf("%d", &f[i][j]);
}
for (int i = ; i <= p; i++)
for (int j = ; j <= f[i][]; j++)
{
swap(a[pos[f[i][]]], a[pos[f[i][j]]]);
swap(pos[f[i][]], pos[f[i][j]]);
}
for (int i = ; i <= n; i++)
printf("%d ", a[i]); return ;
}