# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644394 | Iwanttobreakfree | Naboj (COCI22_naboj) | C++17 | 392 ms | 21184 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>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g (n,vector<int>());
while (m--) {
int a, b;
cin >> a >> b;
a--;b--;
g[b].push_back (a);
}
vector<int> cnt (n);
for (int i = 0; i < n; ++i) for (int x :g[i]) cnt[x]++;
queue<int> q;
for (int i = 0; i < n; ++i) if(!cnt[i]) q.push(i);
vector<int> ans;
while (!q.empty()) {
int u = q.front();
ans.push_back (u);
q.pop();
for (int v:g[u]){
cnt[v]--;
if (!cnt[v])q.push (v);
}
}
if (ans.size() == n) {
cout << n << '\n';
for (auto x : ans) cout << x+1 << ' ' << 1 << '\n';
}
else cout << -1;
}
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... |