답안 #635431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635431 2022-08-26T09:02:02 Z _HDH Naboj (COCI22_naboj) C++11
0 / 110
183 ms 21272 KB
#include <bits/stdc++.h>

using namespace std;

int const N = 2e5 + 1;

vector<int> g[N], h[N];

int main(){
    int n, m; cin >> n >> m;
    while (m--){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        h[b].push_back(a);
    }

    int sign[N] = {};
    memset(sign, -1, sizeof sign);

    for (int i = 1; i <= n; i++){
        if (g[i].size() > 0 && h[i].size() > 0){
            for (auto v: g[i]){
                if (sign[v] == 1){
                    cout << -1;
                    return 0;
                }
                sign[v] = 0;
            }
            for (auto v: h[i]){
                if (sign[v] == 0){
                    cout << -1;
                    return 0;
                }
                sign[v] = 1;
            }
        }
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++)
        if (sign[i] != -1) cnt++;
    cout << cnt << "\n";
    for (int i = 1; i <= n; i++)
        if (sign[i] != -1) cout << i << " " << sign[i] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 5 ms 10452 KB Output is correct
3 Correct 5 ms 10452 KB Output is correct
4 Correct 5 ms 10452 KB Output is correct
5 Correct 5 ms 10476 KB Output is correct
6 Correct 5 ms 10452 KB Output is correct
7 Correct 6 ms 10440 KB Output is correct
8 Incorrect 6 ms 10452 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 21272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 5 ms 10452 KB Output is correct
3 Correct 5 ms 10452 KB Output is correct
4 Correct 5 ms 10452 KB Output is correct
5 Correct 5 ms 10476 KB Output is correct
6 Correct 5 ms 10452 KB Output is correct
7 Correct 6 ms 10440 KB Output is correct
8 Incorrect 6 ms 10452 KB Output isn't correct
9 Halted 0 ms 0 KB -