# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090107 | Onur_Ilgaz | Naboj (COCI22_naboj) | C++17 | 142 ms | 25000 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>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
int32_t main(){
fast
int n, m;
cin >> n >> m;
vector <vector <int> > adj(n + 1);
vector <int> to(n + 1);
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[b].push_back(a);
to[a]++;
}
vector <int> ans, zeros;
for(int i = 1; i <= n; i++) {
if(!to[i]) {
zeros.push_back(i);
}
}
while(!zeros.empty()) {
int node = zeros.back();
ans.push_back(node);
// cout << node << "\n";
zeros.pop_back();
for(auto it:adj[node]) {
to[it]--;
if(to[it] == 0) zeros.push_back(it);
}
}
if(ans.size() != n) {
cout << -1 << "\n";
return 0;
}
cout << n << "\n";
for(auto it:ans) {
cout << it << " " << 1 << "\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... |