# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
849903 | 1075508020060209tc | Povjerenstvo (COI22_povjerenstvo) | C++14 | 412 ms | 43540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int n;int m;
vector<int>er[500005];
int dgr[500005];
int isin[500005];
int has[500005];
signed main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int a;int b;
cin>>a>>b;
er[b].push_back(a);
dgr[a]++;
}
queue<int>q;
for(int i=1;i<=n;i++){
if(dgr[i]==0){
q.push(i);
isin[i]=1;
}
}
while(q.size()){
int nw=q.front();
q.pop();
for(int i=0;i<er[nw].size();i++){
int v=er[nw][i];
dgr[v]--;
if( isin[nw] ){
has[v]=1;
}
if(dgr[v]==0){
if(has[v]==0){
isin[v]=1;
}
q.push(v);
}
}
}
vector<int>ans;
for(int i=1;i<=n;i++){
if(isin[i]){ans.push_back(i);}
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |