답안 #877795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877795 2023-11-23T14:42:59 Z Alora Naboj (COCI22_naboj) C++17
110 / 110
263 ms 30292 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];
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

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);}
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10888 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 10844 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 21332 KB Output is correct
2 Correct 141 ms 21288 KB Output is correct
3 Correct 42 ms 17180 KB Output is correct
4 Correct 92 ms 21332 KB Output is correct
5 Correct 112 ms 21240 KB Output is correct
6 Correct 88 ms 21328 KB Output is correct
7 Correct 93 ms 21332 KB Output is correct
8 Correct 78 ms 19364 KB Output is correct
9 Correct 87 ms 21388 KB Output is correct
10 Correct 99 ms 21332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10888 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 10844 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10864 KB Output is correct
15 Correct 98 ms 21332 KB Output is correct
16 Correct 141 ms 21288 KB Output is correct
17 Correct 42 ms 17180 KB Output is correct
18 Correct 92 ms 21332 KB Output is correct
19 Correct 112 ms 21240 KB Output is correct
20 Correct 88 ms 21328 KB Output is correct
21 Correct 93 ms 21332 KB Output is correct
22 Correct 78 ms 19364 KB Output is correct
23 Correct 87 ms 21388 KB Output is correct
24 Correct 99 ms 21332 KB Output is correct
25 Correct 113 ms 20216 KB Output is correct
26 Correct 133 ms 20244 KB Output is correct
27 Correct 117 ms 20908 KB Output is correct
28 Correct 212 ms 22544 KB Output is correct
29 Correct 91 ms 19996 KB Output is correct
30 Correct 159 ms 28156 KB Output is correct
31 Correct 22 ms 13148 KB Output is correct
32 Correct 128 ms 24384 KB Output is correct
33 Correct 199 ms 29744 KB Output is correct
34 Correct 115 ms 24656 KB Output is correct
35 Correct 253 ms 29540 KB Output is correct
36 Correct 170 ms 24120 KB Output is correct
37 Correct 263 ms 28240 KB Output is correct
38 Correct 191 ms 26436 KB Output is correct
39 Correct 261 ms 29268 KB Output is correct
40 Correct 178 ms 27476 KB Output is correct
41 Correct 158 ms 27488 KB Output is correct
42 Correct 261 ms 30164 KB Output is correct
43 Correct 133 ms 24916 KB Output is correct
44 Correct 235 ms 30292 KB Output is correct
45 Correct 124 ms 24660 KB Output is correct
46 Correct 179 ms 27920 KB Output is correct