From 6756c27bf99da205e0af526a2416d0e548468c7b Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 1 Oct 2024 22:03:35 +0800 Subject: [PATCH] update --- P2615/P2615.cpp | 2 +- P2661/main.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/P2615/P2615.cpp b/P2615/P2615.cpp index f25f159..6bc7ecd 100644 --- a/P2615/P2615.cpp +++ b/P2615/P2615.cpp @@ -4,7 +4,7 @@ using std::cin,std::cout; int main(){ - std::iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0); + std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr); } \ No newline at end of file diff --git a/P2661/main.cpp b/P2661/main.cpp index afb4612..7f5e3c1 100644 --- a/P2661/main.cpp +++ b/P2661/main.cpp @@ -2,24 +2,27 @@ #include #include #include +#include using std::cin,std::cout; const int MAX_N {(int)2e5+5}; int n; -int next[MAX_N]; +std::vector next[MAX_N]; int inDegree[MAX_N]; bool vis[MAX_N]; std::queue q; int ans; +int input; int main(){ std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr); std::cin>>n; for(int i=1;i<=n;i++){ - cin>>next[i]; - inDegree[next[i]]++; + cin>>input; + inDegree[input]++; + next[i].push_back(input); } const auto push_vis = [](int n){ q.push(n); @@ -33,10 +36,16 @@ int main(){ while(q.empty()==false){ int front = q.front(); q.pop(); - if(--inDegree[next[front]]<=0){ - push_vis(next[front]); + for(int i:next[front]){ + if(--inDegree[i]<=0){ + push_vis(i); + } } + } + const auto dfs = [](){ + + }; for(int i=1;i<=n;i++){ if(vis[i])continue; int loop_size {0};