Submission #869364

#TimeUsernameProblemLanguageResultExecution timeMemory
869364TAhmed33Naboj (COCI22_naboj)C++98
110 / 110
378 ms20148 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 25; vector <int> adj[MAXN]; int deg[MAXN], n, m; int main () { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); deg[b]++; } queue <int> cur; for (int i = 1; i <= n; i++) { if (deg[i] == 0) { cur.push(i); } } int cnt = 0; vector <int> topo; while (!cur.empty()) { int k = cur.front(); cur.pop(); cnt++; topo.push_back(k); for (auto j : adj[k]) { deg[j]--; if (deg[j] == 0) { cur.push(j); } } } reverse(topo.begin(), topo.end()); if (cnt != n) { cout << "-1\n"; } else { cout << n << '\n'; for (auto i : topo) cout << i << " 1\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...