Submission #877794

# Submission time Handle Problem Language Result Execution time Memory
877794 2023-11-23T14:42:02 Z Alora Naboj (COCI22_naboj) C++17
40 / 110
190 ms 28244 KB
#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], dem;
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();
        dem++;
        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);
        }
    }
    if(dem < n) {cout << -1; return 0;}
    cout << sl << '\n';
    fid(i, sl, 1) cout << ans[i].f << " " << ans[i].se << '\n';
    return 0;
}

Compilation message

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 time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10892 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10860 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10848 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10900 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 21284 KB Output is correct
2 Correct 115 ms 23752 KB Output is correct
3 Correct 42 ms 18516 KB Output is correct
4 Correct 110 ms 23888 KB Output is correct
5 Correct 104 ms 23892 KB Output is correct
6 Correct 97 ms 23892 KB Output is correct
7 Correct 107 ms 23708 KB Output is correct
8 Correct 73 ms 21220 KB Output is correct
9 Correct 108 ms 23760 KB Output is correct
10 Correct 158 ms 23940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10892 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10860 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10848 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10900 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 123 ms 21284 KB Output is correct
16 Correct 115 ms 23752 KB Output is correct
17 Correct 42 ms 18516 KB Output is correct
18 Correct 110 ms 23888 KB Output is correct
19 Correct 104 ms 23892 KB Output is correct
20 Correct 97 ms 23892 KB Output is correct
21 Correct 107 ms 23708 KB Output is correct
22 Correct 73 ms 21220 KB Output is correct
23 Correct 108 ms 23760 KB Output is correct
24 Correct 158 ms 23940 KB Output is correct
25 Correct 102 ms 25136 KB Output is correct
26 Correct 105 ms 23892 KB Output is correct
27 Correct 190 ms 25728 KB Output is correct
28 Correct 154 ms 28244 KB Output is correct
29 Incorrect 131 ms 24416 KB Output isn't correct
30 Halted 0 ms 0 KB -