Loading...
Submission
# When Author Problem Language CPU Memory
7099 2023-03-03 13:39:30 heisenberg_120 Cheaters C++ 17 3 ms 3564 kb Wrong Answer - 2
Test Cases
# CPU Memory Points
1 3 ms 3564 kb 1 Accepted
2 3 ms 3540 kb 0 Wrong Answer
Source Code
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. const int N = 55;
  5. vector<int> g[N];
  6. vector<bool> vis(N), used(N);
  7.  
  8. void DFS(int cur){
  9. vis[cur] = true;
  10. cout << cur << ' ';
  11. for(auto x : g[cur]){
  12. if(!vis[x]){
  13. DFS(x);
  14. }
  15. }
  16. }
  17.  
  18. signed main(){
  19. ios_base::sync_with_stdio(false);
  20. cin.tie(nullptr);
  21. int tt;
  22. cin >> tt;
  23. while (tt--){
  24. int n;
  25. cin >> n;
  26. for(int i = 0; i <= n; i++){
  27. g[i].clear();
  28. vis[i] = false;
  29. used[i] = false;
  30. }
  31. vector<int> a(n + 1); int boss;
  32. for(int i = 1; i <= n; i++){
  33. cin >> a[i];
  34. if(a[i] == i){
  35. boss = i;
  36. }
  37. }
  38. vector<int> c; c.push_back(boss);
  39. for(int i = 1; i <= n; i++){
  40. if(a[i] == boss and i != boss){
  41. c.push_back(i);
  42. }
  43. }
  44. used[boss] = true;
  45. for(auto x : c){
  46. if(x != boss){
  47. g[boss].push_back(x);
  48. used[x] = true;
  49. }
  50. }
  51. for(auto x : c){
  52. int xx = x - 1, yy = x + 1;
  53. while (yy <= n and !used[yy]){
  54. used[yy] = true;
  55. g[x].push_back(yy);
  56. yy++;
  57. }
  58. while (xx > 0 and !used[xx]){
  59. used[xx] = true;
  60. g[x].push_back(xx);
  61. xx--;
  62. }
  63. }
  64. DFS(boss);
  65. cout << '\n';
  66. }
  67. return 0;
  68. }