Submission #875841

#TimeUsernameProblemLanguageResultExecution timeMemory
875841Mizo_CompilerNaboj (COCI22_naboj)C++17
0 / 110
91 ms16068 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double ld; #define pb push_back #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define F first #define S second const int N = 2e5+5; int n, m, in[N]; vector<int> adj[N]; vector<pair<int, int>> ans; int cnt = 0; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; adj[u].pb(v); in[v]++; } queue<int> q; for (int i = 0; i < n; i++) { if (!in[i])q.push(i); } while (!q.empty()) { int u = q.front(); q.pop(); cnt++; for (auto &v : adj[u]) { if (--in[v] == 0)q.push(v); } if (adj[u].empty())ans.pb({u, 0}); else ans.pb({u, 1}); } if (cnt != n) { cout << -1; return 0; } cout << sz(ans) << "\n"; for (auto &[x, y] : ans)cout << x+1 << " " << y << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...