답안 #750662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750662 2023-05-30T05:41:58 Z GrindMachine Joker (BOI20_joker) C++17
49 / 100
1581 ms 85292 KB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a, b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a, b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

struct DSU {
    vector<int> par, rankk, siz;
    vector<int> weight;
    bool is_bip;

    DSU() {

    }

    DSU(int n) {
        init(n);
    }

    void init(int n) {
        par = vector<int>(n + 1);
        rankk = vector<int>(n + 1);
        siz = vector<int>(n + 1);
        weight = vector<int>(n + 1);
        is_bip = true;
        rep(i, n + 1) create(i);
    }

    void create(int u) {
        par[u] = u;
        rankk[u] = 0;
        siz[u] = 1;
        weight[u] = 0;
    }

    pii find(int u) {
        if (u == par[u]) return {u,0};
        auto [p, cp] = find(par[u]);
        return {p, cp ^ weight[u]};        
    }

    bool same(int u, int v) {
        return find(u).ff == find(v).ff;
    }

    void merge(int u, int v) {
        auto [pu,cu] = find(u);
        auto [pv,cv] = find(v);

        if(pu == pv){
            if(cu == cv){
                is_bip = false;
            }

            return;
        }

        int w = cu ^ cv ^ 1;
        u = pu, v = pv;

        if (rankk[u] == rankk[v]) rankk[u]++;
        if (rankk[u] < rankk[v]) swap(u, v);

        par[v] = u;
        siz[u] += siz[v];
        weight[v] = w;
    }
};

void solve(int test_case)
{
    int n,m,q; cin >> n >> m >> q;
    vector<pii> edges(m+5);
    rep1(i,m) cin >> edges[i].ff >> edges[i].ss;

    if(max({n,m,q}) <= 2000){

        while(q--){
            int l,r; cin >> l >> r;
            DSU dsu(n+5);
     
            rep1(i,m){
                if(i < l or i > r){
                    auto [u,v] = edges[i];
                    dsu.merge(u,v);
                }
            }
     
            if(!dsu.is_bip){
                yes;
            }
            else{
                no;
            }
        }

        return;
    
    }

    bool ans[min(m,200)+5][m+5];
    memset(ans,0,sizeof ans);

    for(int l = 1; l <= min(m,200); ++l){
        DSU dsu(n+5);
        rep1(i,l-1){
            auto [u,v] = edges[i];
            dsu.merge(u,v);
        }

        rev(i,m+1,l){
            if(i <= m){
                auto [u,v] = edges[i];
                dsu.merge(u,v);
            }

            if(!dsu.is_bip){
                rev(j,i-1,l){
                    ans[l][j] = 1;
                }

                break;
            }
        }
    }

    while(q--){
        int l,r; cin >> l >> r;
        if(ans[l][r]) yes;
        else no;
    }
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 38 ms 364 KB Output is correct
30 Correct 59 ms 344 KB Output is correct
31 Correct 72 ms 344 KB Output is correct
32 Correct 60 ms 340 KB Output is correct
33 Correct 51 ms 348 KB Output is correct
34 Correct 61 ms 364 KB Output is correct
35 Correct 68 ms 364 KB Output is correct
36 Correct 38 ms 340 KB Output is correct
37 Correct 63 ms 368 KB Output is correct
38 Correct 79 ms 352 KB Output is correct
39 Correct 49 ms 340 KB Output is correct
40 Correct 51 ms 340 KB Output is correct
41 Correct 48 ms 356 KB Output is correct
42 Correct 47 ms 340 KB Output is correct
43 Correct 80 ms 344 KB Output is correct
44 Correct 90 ms 340 KB Output is correct
45 Correct 86 ms 468 KB Output is correct
46 Correct 82 ms 360 KB Output is correct
47 Correct 50 ms 340 KB Output is correct
48 Correct 54 ms 340 KB Output is correct
49 Correct 53 ms 356 KB Output is correct
50 Correct 58 ms 368 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 57 ms 352 KB Output is correct
53 Correct 61 ms 352 KB Output is correct
54 Correct 71 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 732 ms 43692 KB Output is correct
4 Correct 1552 ms 45140 KB Output is correct
5 Correct 409 ms 45024 KB Output is correct
6 Correct 291 ms 43752 KB Output is correct
7 Correct 273 ms 43564 KB Output is correct
8 Correct 491 ms 42956 KB Output is correct
9 Correct 586 ms 43552 KB Output is correct
10 Correct 1113 ms 45368 KB Output is correct
11 Correct 836 ms 43604 KB Output is correct
12 Correct 973 ms 45040 KB Output is correct
13 Correct 646 ms 42648 KB Output is correct
14 Correct 450 ms 43100 KB Output is correct
15 Correct 896 ms 44388 KB Output is correct
16 Correct 1148 ms 45488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 732 ms 43692 KB Output is correct
30 Correct 1552 ms 45140 KB Output is correct
31 Correct 409 ms 45024 KB Output is correct
32 Correct 291 ms 43752 KB Output is correct
33 Correct 273 ms 43564 KB Output is correct
34 Correct 491 ms 42956 KB Output is correct
35 Correct 586 ms 43552 KB Output is correct
36 Correct 1113 ms 45368 KB Output is correct
37 Correct 836 ms 43604 KB Output is correct
38 Correct 973 ms 45040 KB Output is correct
39 Correct 646 ms 42648 KB Output is correct
40 Correct 450 ms 43100 KB Output is correct
41 Correct 896 ms 44388 KB Output is correct
42 Correct 1148 ms 45488 KB Output is correct
43 Correct 740 ms 43692 KB Output is correct
44 Correct 1581 ms 45392 KB Output is correct
45 Correct 1495 ms 45364 KB Output is correct
46 Correct 244 ms 43944 KB Output is correct
47 Correct 260 ms 43776 KB Output is correct
48 Correct 682 ms 43920 KB Output is correct
49 Correct 1141 ms 45292 KB Output is correct
50 Correct 928 ms 43480 KB Output is correct
51 Correct 955 ms 44416 KB Output is correct
52 Correct 1066 ms 45472 KB Output is correct
53 Correct 525 ms 42656 KB Output is correct
54 Correct 595 ms 43524 KB Output is correct
55 Correct 905 ms 44272 KB Output is correct
56 Correct 1198 ms 45384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 38 ms 364 KB Output is correct
30 Correct 59 ms 344 KB Output is correct
31 Correct 72 ms 344 KB Output is correct
32 Correct 60 ms 340 KB Output is correct
33 Correct 51 ms 348 KB Output is correct
34 Correct 61 ms 364 KB Output is correct
35 Correct 68 ms 364 KB Output is correct
36 Correct 38 ms 340 KB Output is correct
37 Correct 63 ms 368 KB Output is correct
38 Correct 79 ms 352 KB Output is correct
39 Correct 49 ms 340 KB Output is correct
40 Correct 51 ms 340 KB Output is correct
41 Correct 48 ms 356 KB Output is correct
42 Correct 47 ms 340 KB Output is correct
43 Correct 80 ms 344 KB Output is correct
44 Correct 90 ms 340 KB Output is correct
45 Correct 86 ms 468 KB Output is correct
46 Correct 82 ms 360 KB Output is correct
47 Correct 50 ms 340 KB Output is correct
48 Correct 54 ms 340 KB Output is correct
49 Correct 53 ms 356 KB Output is correct
50 Correct 58 ms 368 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 57 ms 352 KB Output is correct
53 Correct 61 ms 352 KB Output is correct
54 Correct 71 ms 340 KB Output is correct
55 Runtime error 730 ms 85292 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 38 ms 364 KB Output is correct
30 Correct 59 ms 344 KB Output is correct
31 Correct 72 ms 344 KB Output is correct
32 Correct 60 ms 340 KB Output is correct
33 Correct 51 ms 348 KB Output is correct
34 Correct 61 ms 364 KB Output is correct
35 Correct 68 ms 364 KB Output is correct
36 Correct 38 ms 340 KB Output is correct
37 Correct 63 ms 368 KB Output is correct
38 Correct 79 ms 352 KB Output is correct
39 Correct 49 ms 340 KB Output is correct
40 Correct 51 ms 340 KB Output is correct
41 Correct 48 ms 356 KB Output is correct
42 Correct 47 ms 340 KB Output is correct
43 Correct 80 ms 344 KB Output is correct
44 Correct 90 ms 340 KB Output is correct
45 Correct 86 ms 468 KB Output is correct
46 Correct 82 ms 360 KB Output is correct
47 Correct 50 ms 340 KB Output is correct
48 Correct 54 ms 340 KB Output is correct
49 Correct 53 ms 356 KB Output is correct
50 Correct 58 ms 368 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 57 ms 352 KB Output is correct
53 Correct 61 ms 352 KB Output is correct
54 Correct 71 ms 340 KB Output is correct
55 Correct 732 ms 43692 KB Output is correct
56 Correct 1552 ms 45140 KB Output is correct
57 Correct 409 ms 45024 KB Output is correct
58 Correct 291 ms 43752 KB Output is correct
59 Correct 273 ms 43564 KB Output is correct
60 Correct 491 ms 42956 KB Output is correct
61 Correct 586 ms 43552 KB Output is correct
62 Correct 1113 ms 45368 KB Output is correct
63 Correct 836 ms 43604 KB Output is correct
64 Correct 973 ms 45040 KB Output is correct
65 Correct 646 ms 42648 KB Output is correct
66 Correct 450 ms 43100 KB Output is correct
67 Correct 896 ms 44388 KB Output is correct
68 Correct 1148 ms 45488 KB Output is correct
69 Correct 740 ms 43692 KB Output is correct
70 Correct 1581 ms 45392 KB Output is correct
71 Correct 1495 ms 45364 KB Output is correct
72 Correct 244 ms 43944 KB Output is correct
73 Correct 260 ms 43776 KB Output is correct
74 Correct 682 ms 43920 KB Output is correct
75 Correct 1141 ms 45292 KB Output is correct
76 Correct 928 ms 43480 KB Output is correct
77 Correct 955 ms 44416 KB Output is correct
78 Correct 1066 ms 45472 KB Output is correct
79 Correct 525 ms 42656 KB Output is correct
80 Correct 595 ms 43524 KB Output is correct
81 Correct 905 ms 44272 KB Output is correct
82 Correct 1198 ms 45384 KB Output is correct
83 Runtime error 730 ms 85292 KB Execution killed with signal 11
84 Halted 0 ms 0 KB -