Submission #43849117
Source Code Expand
Copy
#include <iostream>#include <vector>using namespace std;typedef int node;node nextNode[200001];bool visited[200001];vector<node> ans;void dfs(node inode) {if (visited[inode])return;visited[inode] = true;ans.push_back(inode);node cnode = nextNode[inode];dfs(cnode);}int main() {
#include <iostream> #include <vector> using namespace std; typedef int node; node nextNode[200001]; bool visited[200001]; vector<node> ans; void dfs(node inode) { if (visited[inode]) return; visited[inode] = true; ans.push_back(inode); node cnode = nextNode[inode]; dfs(cnode); } int main() { int N; cin >> N; for (int i = 1; i <= N; i++) cin >> nextNode[i]; dfs(1); node startNode = nextNode[ans.back()]; int index; for (index = 0; index < N; index++) { if (ans[index] == startNode) break; } cout << ans.size() - index << endl; for (int i = index; i < ans.size(); i++) cout << ans[i] << ' '; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Find it! |
User | riverlike14 |
Language | C++ (GCC 9.2.1) |
Score | 350 |
Code Size | 777 Byte |
Status | AC |
Exec Time | 78 ms |
Memory | 11308 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:36:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 36 | for (int i = index; i < ans.size(); i++) | ~~^~~~~~~~~~~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 350 / 350 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 7 ms | 3456 KB |
sample_02.txt | AC | 3 ms | 3420 KB |
sample_03.txt | AC | 2 ms | 3440 KB |
test_01.txt | AC | 2 ms | 3496 KB |
test_02.txt | AC | 3 ms | 3404 KB |
test_03.txt | AC | 2 ms | 3404 KB |
test_04.txt | AC | 2 ms | 3456 KB |
test_05.txt | AC | 2 ms | 3436 KB |
test_06.txt | AC | 2 ms | 3428 KB |
test_07.txt | AC | 3 ms | 3408 KB |
test_08.txt | AC | 2 ms | 3440 KB |
test_09.txt | AC | 3 ms | 3412 KB |
test_10.txt | AC | 2 ms | 3452 KB |
test_11.txt | AC | 2 ms | 3436 KB |
test_12.txt | AC | 2 ms | 3480 KB |
test_13.txt | AC | 2 ms | 3456 KB |
test_14.txt | AC | 2 ms | 3412 KB |
test_15.txt | AC | 2 ms | 3452 KB |
test_16.txt | AC | 2 ms | 3408 KB |
test_17.txt | AC | 3 ms | 3440 KB |
test_18.txt | AC | 2 ms | 3440 KB |
test_19.txt | AC | 53 ms | 4480 KB |
test_20.txt | AC | 51 ms | 4392 KB |
test_21.txt | AC | 52 ms | 4424 KB |
test_22.txt | AC | 52 ms | 4400 KB |
test_23.txt | AC | 50 ms | 4440 KB |
test_24.txt | AC | 50 ms | 4432 KB |
test_25.txt | AC | 51 ms | 4332 KB |
test_26.txt | AC | 55 ms | 4444 KB |
test_27.txt | AC | 50 ms | 4440 KB |
test_28.txt | AC | 51 ms | 4332 KB |
test_29.txt | AC | 49 ms | 4392 KB |
test_30.txt | AC | 50 ms | 4416 KB |
test_31.txt | AC | 78 ms | 11216 KB |
test_32.txt | AC | 76 ms | 11308 KB |
test_33.txt | AC | 76 ms | 11232 KB |
test_34.txt | AC | 74 ms | 11252 KB |
test_35.txt | AC | 74 ms | 11228 KB |
test_36.txt | AC | 67 ms | 9268 KB |
test_37.txt | AC | 61 ms | 8236 KB |
test_38.txt | AC | 56 ms | 5492 KB |
test_39.txt | AC | 53 ms | 4856 KB |
test_40.txt | AC | 61 ms | 7052 KB |
test_41.txt | AC | 60 ms | 6432 KB |
test_42.txt | AC | 54 ms | 5700 KB |
test_43.txt | AC | 56 ms | 6772 KB |
test_44.txt | AC | 52 ms | 4836 KB |
test_45.txt | AC | 54 ms | 5020 KB |
test_46.txt | AC | 61 ms | 9212 KB |
test_47.txt | AC | 61 ms | 11072 KB |
test_48.txt | AC | 52 ms | 5504 KB |
test_49.txt | AC | 48 ms | 4240 KB |
test_50.txt | AC | 48 ms | 4272 KB |
test_51.txt | AC | 45 ms | 4196 KB |