Submission #782005

#TimeUsernameProblemLanguageResultExecution timeMemory
782005Owen11Naboj (COCI22_naboj)C++14
110 / 110
376 ms20584 KiB
#include <bits/stdc++.h> using namespace std; # define int long long # define fir first # define sec second # define pb push_back const int cnst = 2e5+5; bool mutipletestcase = 0; //bool debug = false; int x[cnst]; vector<int> vec[cnst]; void solve() { int n, m; cin >> n >> m; for(int i = 1; i<=m; i++) { int a, b; cin >> a >> b; vec[b].pb(a); x[a]++; } queue<int> q; int done = 0; for(int i = 1; i<=n; i++) { if(!x[i]) q.push(i), done++; } vector<pair<int, int>> ans; while(!q.empty()) { int a = q.front(); q.pop(); for(auto v: vec[a]) { x[v]--; if(!x[v]) { q.push(v); ans.pb({v, 1}); done++; } } if(done == n) break; } if(done == n) { cout << ans.size() << endl; for(auto v: ans) cout << v.fir << " " << v.sec << endl; } else cout << -1 << endl; } signed main() { ios_base::sync_with_stdio(false); int t = 1; if(mutipletestcase) cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...