답안 #931421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931421 2024-02-21T18:45:13 Z qwusha Joker (BOI20_joker) C++17
14 / 100
112 ms 8920 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ll inf = 1e9;
const ld eps = 1e-8;
const ll logs = 32;
#include <cmath>
bool ch = 0;
vector<vector<pair<ll, ll>>> g;
vector<bool> ok;
vector<ll> col;

void dfs(ll v, ll c = 0) {
    col[v] = c;
    for (auto [u, ind] : g[v]) {
        if (!ok[ind]) {
            continue;
        }
        if (col[u] == -1)
            dfs(u, 1 - c);
        else if (col[u] == col[v])
            ch = 1;
    }
}


struct dsu {
    vector<ll> par, dist, sz;
    void init(ll n) {
        par.resize(n);
        dist.resize(n);
        sz.resize(n);
        for (ll i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 1;
        }
    }
    ll get_par(ll v) {
        if (v == par[v])
            return v;
        ll ans = get_par(par[v]);
        par[v] = ans;
        return ans;
    }
    ll get_dist(ll v) {
        if (v == par[v])
            return 0;
        return (dist[v] + get_dist(par[v])) % 2;
    }
    void union_(ll v, ll u) {
        ll nv = get_par(v);
        ll nu = get_par(u);
        if (nv == nu) {
            if (get_dist(v) == get_dist(u))
                ch = 1;
            return;
        }
        if (sz[nu] > sz[nv])
            swap(nv, nu);
        par[nu] = nv;
        dist[nu] = 1;
    }
};


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, q;
    cin >> n >> m >> q;
    if (n <= 2000 && m <= 2000 && q <= 2000) {
        g.resize(n);
        ok.resize(m, 1);
        col.resize(n);
        for (ll i = 0; i < m; i++) {
            ll v, u;
            cin >> v >> u;
            g[v - 1].push_back({u - 1, i});
            g[u - 1].push_back({v - 1, i});
        }
        for (ll qw = 0; qw < q; qw++) {
            ll l, r;
            cin >> l >> r;
            for (ll i = 0; i < m; i++) {
                if (l - 1 <= i && i < r)
                    ok[i] = 0;
                else
                    ok[i] = 1;
            }
            for (ll i = 0; i < n; i++) {
                col[i] = -1;
            }
            bool check = 0;
            for (ll i = 0; i < n; i++) {
                if (col[i] == -1) {
                    ch = 0;
                    dfs(i);
                    if (ch)
                        check = 1;
                }
            }
            if (check) {
                cout << "YES" << '\n';
            } else {
                cout << "NO" << '\n';
            }
        }
    } else {
        vector<pair<ll, ll>> vert(m);
        for (ll i = 0; i < m; i++) {
            ll v, u;
            cin >> v >> u;
            vert[i] = {v - 1, u - 1};
        }
        reverse(vert.begin(), vert.end());
        ll val = -1;
        dsu dsu;
        dsu.init(n);
        for (ll i = 0; i < m; i++) {
            auto [v, u] = vert[i];
            ch = 0;
            dsu.union_(v, u);
            if (ch) {
                val = (m - i);
                break;
            }
        }
        for (ll qw = 0; qw < q; qw++) {
            ll l, r;
            cin >> l >> r;
            if (r < val)
                cout << "YES" << '\n';
            else
                cout << "NO" << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 43 ms 348 KB Output is correct
30 Correct 105 ms 604 KB Output is correct
31 Correct 107 ms 636 KB Output is correct
32 Correct 83 ms 600 KB Output is correct
33 Correct 67 ms 600 KB Output is correct
34 Correct 110 ms 600 KB Output is correct
35 Correct 112 ms 604 KB Output is correct
36 Correct 35 ms 604 KB Output is correct
37 Correct 61 ms 640 KB Output is correct
38 Correct 50 ms 600 KB Output is correct
39 Correct 76 ms 604 KB Output is correct
40 Correct 70 ms 876 KB Output is correct
41 Correct 72 ms 620 KB Output is correct
42 Correct 73 ms 628 KB Output is correct
43 Correct 56 ms 600 KB Output is correct
44 Correct 71 ms 616 KB Output is correct
45 Correct 84 ms 632 KB Output is correct
46 Correct 88 ms 632 KB Output is correct
47 Correct 70 ms 612 KB Output is correct
48 Correct 78 ms 604 KB Output is correct
49 Correct 89 ms 600 KB Output is correct
50 Correct 103 ms 604 KB Output is correct
51 Correct 73 ms 604 KB Output is correct
52 Correct 82 ms 616 KB Output is correct
53 Correct 94 ms 600 KB Output is correct
54 Correct 111 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 55 ms 6736 KB Output is correct
4 Correct 56 ms 8920 KB Output is correct
5 Incorrect 56 ms 8272 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 55 ms 6736 KB Output is correct
30 Correct 56 ms 8920 KB Output is correct
31 Incorrect 56 ms 8272 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 43 ms 348 KB Output is correct
30 Correct 105 ms 604 KB Output is correct
31 Correct 107 ms 636 KB Output is correct
32 Correct 83 ms 600 KB Output is correct
33 Correct 67 ms 600 KB Output is correct
34 Correct 110 ms 600 KB Output is correct
35 Correct 112 ms 604 KB Output is correct
36 Correct 35 ms 604 KB Output is correct
37 Correct 61 ms 640 KB Output is correct
38 Correct 50 ms 600 KB Output is correct
39 Correct 76 ms 604 KB Output is correct
40 Correct 70 ms 876 KB Output is correct
41 Correct 72 ms 620 KB Output is correct
42 Correct 73 ms 628 KB Output is correct
43 Correct 56 ms 600 KB Output is correct
44 Correct 71 ms 616 KB Output is correct
45 Correct 84 ms 632 KB Output is correct
46 Correct 88 ms 632 KB Output is correct
47 Correct 70 ms 612 KB Output is correct
48 Correct 78 ms 604 KB Output is correct
49 Correct 89 ms 600 KB Output is correct
50 Correct 103 ms 604 KB Output is correct
51 Correct 73 ms 604 KB Output is correct
52 Correct 82 ms 616 KB Output is correct
53 Correct 94 ms 600 KB Output is correct
54 Correct 111 ms 604 KB Output is correct
55 Incorrect 27 ms 6232 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 43 ms 348 KB Output is correct
30 Correct 105 ms 604 KB Output is correct
31 Correct 107 ms 636 KB Output is correct
32 Correct 83 ms 600 KB Output is correct
33 Correct 67 ms 600 KB Output is correct
34 Correct 110 ms 600 KB Output is correct
35 Correct 112 ms 604 KB Output is correct
36 Correct 35 ms 604 KB Output is correct
37 Correct 61 ms 640 KB Output is correct
38 Correct 50 ms 600 KB Output is correct
39 Correct 76 ms 604 KB Output is correct
40 Correct 70 ms 876 KB Output is correct
41 Correct 72 ms 620 KB Output is correct
42 Correct 73 ms 628 KB Output is correct
43 Correct 56 ms 600 KB Output is correct
44 Correct 71 ms 616 KB Output is correct
45 Correct 84 ms 632 KB Output is correct
46 Correct 88 ms 632 KB Output is correct
47 Correct 70 ms 612 KB Output is correct
48 Correct 78 ms 604 KB Output is correct
49 Correct 89 ms 600 KB Output is correct
50 Correct 103 ms 604 KB Output is correct
51 Correct 73 ms 604 KB Output is correct
52 Correct 82 ms 616 KB Output is correct
53 Correct 94 ms 600 KB Output is correct
54 Correct 111 ms 604 KB Output is correct
55 Correct 55 ms 6736 KB Output is correct
56 Correct 56 ms 8920 KB Output is correct
57 Incorrect 56 ms 8272 KB Output isn't correct
58 Halted 0 ms 0 KB -