| Task: | Terrible security |
| Sender: | aalto26fm_023 |
| Submission time: | 2026-10-05 17:36:07 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:26:27: error: a function-definition is not allowed here before '{' token
26 | int dfs(int s, int r) {
| ^
input/code.cpp:41:25: error: invalid use of member function 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::begin() const [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]' (did you forget the '()' ?)
41 | val = dfs(*node.begin,1)
| ~~~~~^~~~~
| ()
input/code.cpp:41:15: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
41 | val = dfs(*node.begin,1)
| ^~~
| ffs
input/code.cpp:42:21: error: 'i' was not declared in this scope
42 | for (int i; i<n;i++){
| ^Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
int q;
cin>>n;
cin>>q;
vector<int> k(n);
for (int i =0; i <n;i++){
cin>>k[i];
}
vector<bool> visited(n);
vector<int> sizecycle(n);
int mark =0;
vector<int> marked(n,-1);
set<int> node;
for (int i; i<n; i++){
node.insert(i);
}
int dfs(int s, int r) {
if (visited[s]) {
return r;
}
else {
marked[s]=mark;
node.erase(s);
r++
}
visited[s] = true;
dfs(k[s]);
}
while (!node.empty()){
int val;
val = dfs(*node.begin,1)
for (int i; i<n;i++){
if (marked[i]==mark){
sizecycle[i]= val
}
}
mark++;
}
for (int i=0; i<q; i++){
int x;
cin>>x;
cout<<sizecycle[x];
}
}