Submission #704910

#TimeUsernameProblemLanguageResultExecution timeMemory
704910guagua0407Naboj (COCI22_naboj)C++17
0 / 110
123 ms19376 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define all(x) x.begin(),x.end() int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; vector<int> in(n,0); vector<bool> visited(n,false); vector<int> adj[n],adjr[n]; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a--; b--; in[a]++; adj[b].push_back(a); } queue<int> q; for(int i=0;i<n;i++){ if(in[i]==0) q.push(i); } vector<pair<int,int>> ans; while(!q.empty()){ int v=q.front(); q.pop(); visited[v]=true; ans.push_back({v,0}); for(auto u:adj[v]){ if(visited[u]){ cout<<-1; return 0; } in[u]--; if(in[u]==0){ q.push(u); } } } reverse(all(ans)); for(auto v:ans){ cout<<v.f+1<<' '<<v.s<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...