Submission #73303930
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
void O_O() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> ans(n + 1);
auto dfs = [&](auto& dfs, int i) -> int {
if (i == a[i]) return ans[i] = a[i];
if (ans[i]) return ans[i];
return ans[i] = dfs(dfs, a[i]);
};
for (int i = 1; i <= n; i++) {
dfs(dfs, i);
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
//cin >> TC;
while (TC--) {
O_O();
if (TC) cout << '\n';
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Sugoroku Destination |
| User | Mariouma |
| Language | C++23 (GCC 15.2.0) |
| Score | 300 |
| Code Size | 748 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 15648 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3612 KiB |
| 00_sample_01.txt | AC | 1 ms | 3588 KiB |
| 00_sample_02.txt | AC | 1 ms | 3464 KiB |
| 01_random_03.txt | AC | 42 ms | 7952 KiB |
| 01_random_04.txt | AC | 43 ms | 7952 KiB |
| 01_random_05.txt | AC | 41 ms | 7960 KiB |
| 01_random_06.txt | AC | 41 ms | 7956 KiB |
| 01_random_07.txt | AC | 41 ms | 7964 KiB |
| 01_random_08.txt | AC | 42 ms | 7964 KiB |
| 01_random_09.txt | AC | 42 ms | 7952 KiB |
| 01_random_10.txt | AC | 42 ms | 7964 KiB |
| 01_random_11.txt | AC | 17 ms | 4872 KiB |
| 01_random_12.txt | AC | 14 ms | 4524 KiB |
| 01_random_13.txt | AC | 37 ms | 7244 KiB |
| 01_random_14.txt | AC | 4 ms | 3704 KiB |
| 01_random_15.txt | AC | 41 ms | 7948 KiB |
| 01_random_16.txt | AC | 2 ms | 3448 KiB |
| 01_random_17.txt | AC | 41 ms | 15648 KiB |