update
This commit is contained in:
parent
f5b3a1cfcb
commit
6756c27bf9
@ -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);
|
||||
|
||||
|
||||
}
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user