Submission #877795

#TimeUsernameProblemLanguageResultExecution timeMemory
877795AloraNaboj (COCI22_naboj)C++17
110 / 110
263 ms30292 KiB
#include <bits/stdc++.h> #define Alora "cownav" #define fi(i,a,b) for(int i = a; i <= b; i++) #define fid(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define f first #define se second #define pii pair<int, int> #define getbit(i, j) ((i >> j) & 1) #define all(v) v.begin(), v.end() #define pb push_back #define maxn 300005 const int M = 1e9 + 7; using namespace std; int n, m, sl, cnt[maxn][4]; pii ans[maxn]; queue <int> q; vector <int> g[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); if(fopen(Alora".inp", "r")){ freopen(Alora".inp", "r", stdin); freopen(Alora".out", "w", stdout);} cin >> n >> m; fi(i, 1, m){ int u, v; cin >> u >> v; g[u].pb(v); cnt[u][1]++; g[v].pb(u); cnt[v][0]++; } fi(u, 1, n) if(cnt[u][1] == 0 || cnt[u][0] == 0) q.push(u); while(q.size()){ int u = q.front(); q.pop(); if(cnt[u][1] + cnt[u][0] == 0) continue; int t = (cnt[u][0] > 0 ? 0 : 1); cnt[u][t] = 0; //cout << u << " " << t << endl; ans[++sl] = {u, t}; for(auto v: g[u]) if(cnt[v][1 - t]){ cnt[v][1 - t]--; if(cnt[v][1 - t] == 0) q.push(v); } } fi(i, 1, n) if(cnt[i][0] + cnt[i][1]) {cout << -1; return 0;} cout << sl << '\n'; fid(i, sl, 1) cout << ans[i].f << " " << ans[i].se << '\n'; return 0; }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen(Alora".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
naboj.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen(Alora".out", "w", stdout);}
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...