From c1dc73f77230c54fced44e9d070eddd52dbde48c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Fri, 30 Aug 2024 18:04:27 +0800 Subject: [PATCH] update --- 20240830/P2661/P2661.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ 20240830/P4089/P4089.cpp | 40 ++++++++++++++++++++++++++++++++ xmake.lua | 9 +++++++- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 20240830/P2661/P2661.cpp create mode 100644 20240830/P4089/P4089.cpp diff --git a/20240830/P2661/P2661.cpp b/20240830/P2661/P2661.cpp new file mode 100644 index 0000000..30f5800 --- /dev/null +++ b/20240830/P2661/P2661.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +const int MAX_N{int(2e5+5)}; + +int in_degree[MAX_N]{},n,next[MAX_N]; +std::queue q; +bool vis[MAX_N]; + +int main(){ + std::cin>>n; + for(int i=1;i<=n;i++){ + int input; + std::cin>>input; + in_degree[input]++; + next[i]=input; + } + for(int i=1;i<=n;i++){ + if(in_degree[i]==0){ + q.push(i); + } + } + + while(q.empty()==false){ + int top = q.front(); + in_degree[next[top]]--; + q.pop(); + if(in_degree[next[top]]==0){ + q.push(next[top]); + } + } + + int ans{0}; + + for(int i=1;i<=n;i++){ + if(in_degree[i]!=0 && vis[i]==false){ + int begin{i},s{1}; + int now{next[begin]}; + vis[begin]=true; + while(now!=begin){ + vis[now]=true; + s++; + now=next[now]; + } + ans=std::max(ans,s); + } + } + + std::cout< +#include +const int MAX_N{int(1e5+5)}; + +int in_degree[MAX_N]{},n,next[MAX_N]; +std::queue q; + +void find(int num){ + +} + +int main(){ + std::cin>>n; + for(int i=1;i<=n;i++){ + int input; + std::cin>>input; + in_degree[input]++; + next[i]=input; + } + int zero_in_degree_dir = -1; + int cnt{}; + for(int i=1;i<=n;i++){ + if(in_degree[i]==0){ + q.push(i); + cnt++; + } + } + + while(q.empty()==false){ + int top = q.front(); + in_degree[next[top]]--; + q.pop(); + if(in_degree[next[top]]==0){ + q.push(next[top]); + cnt++; + } + } + + std::cout<<(n-cnt)<<"\n"; +} \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 32030f4..234c957 100644 --- a/xmake.lua +++ b/xmake.lua @@ -7,6 +7,7 @@ if is_mode("release") then add_cxxflags("-march=native") end set_languages("c++17") +set_warnings("all") target("P1158") set_rundir("20240821/P1158") @@ -28,4 +29,10 @@ target("P2615") add_files("20240828/P2615/P2615.cpp") target("B4015") - add_files("20240829/B4015/B4015.cpp") \ No newline at end of file + add_files("20240829/B4015/B4015.cpp") + +target("P4089") + add_files("20240830/P4089/P4089.cpp") + +target("P2661") + add_files("20240830/P2661/P2661.cpp") \ No newline at end of file