답안 #765280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765280 2023-06-24T10:15:24 Z oyber Joker (BOI20_joker) C++14
25 / 100
73 ms 5580 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

vector<int> u;
vector<int> s;
vector<int> p;

int find(int n) {
    if (u[n] == n) return n;
    return find(u[n]);
}

int parity(int n) {
    if (u[n] == n) return 0;
    return parity(u[n])^p[n];
}

void unite(int a, int b) {
    int ap = find(a);
    int bp = find(b);
    if (s[bp] > s[ap]) {
        swap(a, b);
        swap(ap, bp);
    }
    u[bp] = ap;
    s[ap] += s[bp];
    if (parity(a) == parity(b)) {
        p[bp] = 1;
    }
}

int main() {
    int n, m, qn;
    scanf("%d %d %d", &n, &m, &qn);

    u.resize(n);
    s.resize(n, 1);
    p.resize(n);

    for (int i = 0; i < n; i++) {
        u[i] = i;
    }

    vector<pair<int, int>> e(m);
    for (int i = 0; i < m; i++) {
        int a, b; 
        scanf("%d %d", &a, &b);
        a--;b--;
        e[i] = make_pair(a, b);
        //printf("%d %d %d\n", a, b, i);
    }

    int cycle = -1;
    for (int j = m-1; j >= 0; j--) {
        int a = e[j].first;
        int b = e[j].second;
        //printf("%d: (%d %d) (%d %d) (%d %d)\n", j, a, b, find(a), find(b), parity(a), parity(b));
        if (find(a) == find(b)) {
            if (parity(a) == parity(b)) {
                cycle = j;
                break;
            }
        } else {
            unite(a, b);
        }
    }
    //printf("%d\n", cycle);
    for (int i = 0; i < qn; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        l--;r--;

        if (r < cycle) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d %d %d", &n, &m, &qn);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Joker.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 73 ms 4808 KB Output is correct
4 Correct 66 ms 5580 KB Output is correct
5 Correct 63 ms 5500 KB Output is correct
6 Correct 63 ms 4184 KB Output is correct
7 Correct 62 ms 4172 KB Output is correct
8 Correct 62 ms 4044 KB Output is correct
9 Correct 63 ms 4416 KB Output is correct
10 Correct 63 ms 5540 KB Output is correct
11 Correct 65 ms 4168 KB Output is correct
12 Correct 62 ms 5120 KB Output is correct
13 Correct 64 ms 3228 KB Output is correct
14 Correct 61 ms 3756 KB Output is correct
15 Correct 63 ms 4776 KB Output is correct
16 Correct 62 ms 5356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 284 KB Output isn't correct
4 Halted 0 ms 0 KB -