This commit is contained in:
Zengtudor 2024-10-01 22:03:35 +08:00
parent f5b3a1cfcb
commit 6756c27bf9
2 changed files with 15 additions and 6 deletions

View File

@ -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);
}

View File

@ -2,24 +2,27 @@
#include <iostream>
#include <istream>
#include <queue>
#include<vector>
using std::cin,std::cout;
const int MAX_N {(int)2e5+5};
int n;
int next[MAX_N];
std::vector<int> next[MAX_N];
int inDegree[MAX_N];
bool vis[MAX_N];
std::queue<int> 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};