update
This commit is contained in:
parent
0caa758c70
commit
c1dc73f772
50
20240830/P2661/P2661.cpp
Normal file
50
20240830/P2661/P2661.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
const int MAX_N{int(2e5+5)};
|
||||
|
||||
int in_degree[MAX_N]{},n,next[MAX_N];
|
||||
std::queue<int> 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<<ans<<"\n";
|
||||
}
|
40
20240830/P4089/P4089.cpp
Normal file
40
20240830/P4089/P4089.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
const int MAX_N{int(1e5+5)};
|
||||
|
||||
int in_degree[MAX_N]{},n,next[MAX_N];
|
||||
std::queue<int> 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";
|
||||
}
|
@ -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")
|
||||
add_files("20240829/B4015/B4015.cpp")
|
||||
|
||||
target("P4089")
|
||||
add_files("20240830/P4089/P4089.cpp")
|
||||
|
||||
target("P2661")
|
||||
add_files("20240830/P2661/P2661.cpp")
|
Loading…
Reference in New Issue
Block a user