diff --git a/CMakeLists.txt b/CMakeLists.txt index a386677..85ca2c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,12 +5,12 @@ add_compile_options(-Wall) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - message("Is in [Release] mode") -else() - message("Is in [NotRelease] mode") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) endif() +message("Build type is [${CMAKE_BUILD_TYPE}]") project(alogrithm_2024) diff --git a/P2661/main.cpp b/P2661/main.cpp index 294989d..b1c16e5 100644 --- a/P2661/main.cpp +++ b/P2661/main.cpp @@ -1,3 +1,53 @@ +#include +#include +#include +#include + +using std::cin,std::cout; + +const int MAX_N {(int)2e5+5}; +int n; +int next[MAX_N]; +int inDegree[MAX_N]; +bool vis[MAX_N]; +std::queue q; +int ans; + int main(){ - + std::iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0); + + std::cin>>n; + for(int i=1;i<=n;i++){ + cin>>next[i]; + inDegree[next[i]]++; + } + const auto push_vis = [](int n){ + q.push(n); + vis[n]=true; + }; + for(int i=1;i<=n;i++){ + if(inDegree[i]<=0){ + push_vis(i); + } + } + while(q.empty()==false){ + int front = q.front(); + q.pop(); + if(--inDegree[next[front]]<=0){ + push_vis(next[front]); + } + } + for(int i=1;i<=n;i++){ + if(vis[i])continue; + int loop_size {0}; + int start {i}; + int now {start}; + do{ + vis[now]=true; + now=next[now]; + loop_size++; + }while(now!=start); + ans=std::max(ans,loop_size); + } + std::cout<