Submission #704886

#TimeUsernameProblemLanguageResultExecution timeMemory
704886guagua0407Naboj (COCI22_naboj)C++17
0 / 110
222 ms23552 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> inout(n,0),deg(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--; inout[a]--; inout[b]++; deg[a]++; deg[b]++; adj[b].push_back(a); adjr[a].push_back(b); } queue<int> q; for(int i=0;i<n;i++){ if(deg[i]==abs(inout[i])){ visited[i]=true; q.push(i); } } vector<pair<int,int>> ans; while(!q.empty()){ int v=q.front(); q.pop(); ans.push_back({v+1,(inout[v]<0?1:0)}); for(auto u:adj[v]){ //if(visited[u]) continue; inout[u]++; deg[u]--; if(deg[u]==abs(inout[u])){ if(!visited[u]){ visited[u]=true; q.push(u); } } } for(auto u:adjr[v]){ //if(visited[u]) continue; inout[u]--; deg[u]--; if(deg[u]==abs(inout[u])){ if(!visited[u]){ visited[u]=true; q.push(u); } } } } for(int i=0;i<n;i++){ if(deg[i]>0){ cout<<-1; return 0; } } reverse(all(ans)); for(auto v:ans){ cout<<v.f<<' '<<v.s<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...