#include using namespace std; #include using namespace atcoder; int main(void) { int n; cin >> n; int m; cin >> m; vector t(m); vector> s(m); vector a(n); for(int i=0;i> t[i]; s[i].resize(t[i]); for(int j=0;j> s[i][j]; --s[i][j]; } int tmp=a[s[i][t[i]-1]]; for(int j=t[i]-1;j>0;--j){ a[s[i][j]]=a[s[i][j-1]]; } a[s[i][0]]=tmp; } dsu g(n); for(int i=0;i