답안 #450444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
450444 2021-08-02T22:23:18 Z mjhmjh1104 Joker (BOI20_joker) C++17
0 / 100
100 ms 7800 KB
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;

int uf[200006], sz[200006], ds[200006];

int _find(int x) {
    if (uf[x] == -1) return x;
    return _find(uf[x]);
}

int _dist(int x) {
    if (uf[x] == -1) return 0;
    return ds[x] + _dist(uf[x]);
}

bool _merge(int x, int y) {
    x = _find(x), y = _find(y);
    if (x != y) {
        if (sz[x] > sz[y]) uf[y] = x, sz[x] += sz[y], ds[y]++;
        else uf[x] = y, sz[y] += sz[x], ds[x]++;
        return true;
    }
    return false;
}

int n, m, q;
vector<pair<int, int>> edges;

int main() {
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--, v--;
        edges.push_back({ u, v });
    }
    for (int i = 0; i < n; i++) uf[i] = -1, sz[i] = 1, ds[i] = 0;
    int x = -1;
    for (int i = m - 1; i >= 0; i--) if (!_merge(edges[i].first, edges[i].second) && (_dist(edges[i].first) + _dist(edges[i].second) + 1) % 2) {
        x = i;
        break;
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        scanf("%d%d", &l, &r);
        l--, r--;
        if (r > x) puts("NO");
        else puts("YES");
    }
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
Joker.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 100 ms 7800 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -