# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
847093 | Pacybwoah | Naboj (COCI22_naboj) | C++17 | 159 ms | 20208 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<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
vector<int> deg(n+1);
vector<vector<int> > graph(n+1);
int a,b;
for(int i=0;i<m;i++){
cin>>a>>b;
deg[b]++;
graph[a].push_back(b);
}
vector<int> topo;
queue<int> q;
for(int i=1;i<=n;i++) if(deg[i]==0) q.push(i);
while(!q.empty()){
int node=q.front();
q.pop();
topo.push_back(node);
for(auto x:graph[node]){
deg[x]--;
if(deg[x]==0) q.push(x);
}
}
if(topo.size()!=n) cout<<-1;
else {cout<<n<<"\n";for(auto x:topo) cout<<x<<' '<<0<<"\n";}
}
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... |