# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852284 | Trisanu_Das | Naboj (COCI22_naboj) | C++17 | 248 ms | 20268 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;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> deg(n + 1), adj[n + 1], topo;
int a, b;
while(m--){
cin >> a >> b;
deg[b]++;
adj[a].push_back(b);
}
queue<int> q;
for(int i = 1; i <= n; i++) if(deg[i] == 0) q.push(i);
while(!q.empty()){
int u = q.front(); q.pop();
topo.push_back(u);
for(auto v : adj[u]){
deg[v]--;
if(deg[v] == 0) q.push(v);
}
}
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... |