# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
983709 | Sandarach151 | Naboj (COCI22_naboj) | C++17 | 181 ms | 20204 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_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> down[n];
vector<int> topsort;
int edge[n] = { 0 };
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
a--;
b--;
down[a].push_back(b);
edge[b]++;
}
queue<int> noedge;
for(int i=0; i<n; i++){
if(edge[i]==0){
noedge.push(i);
}
}
while(!noedge.empty()){
int cur = noedge.front();
noedge.pop();
topsort.push_back(cur);
for(auto u : down[cur]){
edge[u]--;
if(edge[u]==0){
noedge.push(u);
}
}
}
// for(auto u : topsort){
// cout << u << ' ';
// }
if(topsort.size()!=n){
cout << -1 << '\n';
}
else{
cout << n-1 << '\n';
for(int i=n-2; i>=0; i--){
cout << topsort[i]+1 << ' ' << 1 << '\n';
}
}
return 0;
}
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... |