제출 #1125388

#제출 시각아이디문제언어결과실행 시간메모리
1125388SalihSahinNaboj (COCI22_naboj)C++20
0 / 110
363 ms18060 KiB
#include <bits/stdc++.h> #define pb push_back #define int long long using namespace std; const int mod = 998244353; const int N = 1e5 + 10; const int inf = 1e17; int32_t main(){ int n, m; cin>>n>>m; vector<int> in(n+1), out(n+1), adj[n+1]; for(int i = 0; i < m; i++){ int u, v; cin>>u>>v; out[u]++; in[v]++; adj[v].pb(u); } queue<int> q; for(int i = 1; i <= n; i++){ if(!out[i]) q.push(i); } vector<pair<int, int> > ans; int vis = 0; while(!q.empty()){ int x = q.front(); q.pop(); vis++; ans.pb({x, 1}); for(auto itr: adj[x]){ out[itr]--; if(!out[itr]) q.push(itr); } } if(vis != n) cout<<-1<<endl; else{ cout<<ans.size()<<endl; reverse(ans.begin(), ans.end()); for(int i = 0; i < n; i++){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...