Loading...
Submission
Id When Author Problem Language CPU Memory Verdict
16965 2024-04-23 16:54:30 ewu_intra24_mock_u_126 Cheaters C++ 14 1 ms 3360 kb Accepted
Test Cases
CPU Memory Verdict
1 1 ms 3284 kb Accepted
2 1 ms 3360 kb Accepted
Source Code
program.cpp
Download
  1. #include <bits/stdc++.h>
  2.  
  3. using ll = long long;
  4. using namespace std;
  5.  
  6. void solve() {
  7. int n, c;
  8. cin >> n;
  9. vector<int> a(n), ix(n + 1);
  10. for (int i = 0; i < n; i++) {
  11. cin >> a[i];
  12. if (i + 1 == a[i]) {
  13. c = a[i];
  14. continue;
  15. }
  16. ix[a[i]] = i + 1;
  17. }
  18.  
  19. while (c) {
  20. cout << c << " ";
  21. c = ix[c];
  22. }
  23. cout << "\n";
  24. }
  25.  
  26. int main() {
  27. ios_base::sync_with_stdio(false);
  28. cin.tie(nullptr);
  29. int t = 1;
  30. cin >> t;
  31. for (int i = 1; i <= t; i++) {
  32. // cout << "Case no: " << t << "\n";
  33. solve();
  34. }
  35. }