fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. int n, m, moebuta;
  9. cin >> n >> m >> moebuta;
  10. vector<vector<int>> op(m);
  11. for (int i = 0; i < m; i++) {
  12. int c;
  13. cin >> c;
  14. op[i].resize(c);
  15. for (int j = 0; j < c; j++) {
  16. cin >> op[i][j];
  17. op[i][j]--;
  18. }
  19. }
  20. vector<int> t(n);
  21. vector<int> res(n);
  22. iota(res.begin(), res.end(), 0);
  23. for (int i = m - 1; i >= 0; i--) {
  24. fill(t.begin(), t.end(), -1);
  25. int sz = (int) op[i].size();
  26. for (int j = 0; j < sz - 1; j++) {
  27. t[op[i][j]] = op[i][j + 1];
  28. }
  29. if (sz > 1) {
  30. t[op[i][sz - 1]] = op[i][0];
  31. }
  32. for (int i = 0; i < n; i++) {
  33. if (t[res[i]] != -1) {
  34. res[i] = t[res[i]];
  35. }
  36. }
  37. }
  38. for (int i = 0; i < n; i++) {
  39. cout << res[i] + 1 << " \n"[i == n - 1];
  40. }
  41. cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << '\n';
  42. return 0;
  43. }
  44.  
Success #stdin #stdout #stderr 0s 4548KB
stdin
4 3 2
2 4 1
2 3 1
2 2 1
stdout
2 3 4 1
stderr
Time: 0.00356