Submission #689309

# Submission time Handle Problem Language Result Execution time Memory
689309 2023-01-28T06:36:08 Z saayan007 Joker (BOI20_joker) C++17
0 / 100
2 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;

#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first 
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll mxn = 2e5L + 1;
ll n, m, q;
vpl adj[mxn];
bool vis[mxn] = {};
ll dep[mxn] = {};

struct UFDS {
    vl sz;
    vl lnk;
    vl ene;

    UFDS(ll N) {
        sz = vl(N, 1);
        lnk = vl(N);
        iota(all(lnk), 0);
        ene = vl(N, -1);
    }

    ll find(ll a) {
        if(a == lnk[a]) {
            return a;
        }

        return lnk[a] = find(lnk[a]);
    }

    bool same(ll a, ll b) {
        return find(a) == find(b);
    }

    ll unite(ll a, ll b) {
        if(a == -1)
            return b;
        if(b == -1)
            return a;
        a = find(a);
        b = find(b);

        if(a == b)
            return a;

        if(sz[a] < sz[b])
            swap(a, b);

        lnk[b] = a;
        sz[a] += sz[b];

        return a;
    }

    bool makeEne(ll a, ll b) {
        a = find(a);
        b = find(b);

        if(a == b) {
            return 0;
        }

        ll c = ene[a];
        ll d = ene[b];

        a = unite(a, d);
        c = unite(b, c);

        ene[a] = c;
        if(c != -1) {
            ene[c] = a;
        }

        return 1;
    }
};

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> q;
    pl edge[m + 1];
    fur(i, 1, m) {
        cin >> edge[i].fr >> edge[i].sc;
    }

    UFDS uf(n + 1);
    ll odd_if = m + 1;
    ruf(i, m, 1) {
        if(!uf.makeEne(edge[i].fr, edge[i].sc)) {
            odd_if = i;
            break;
        }
    }
    while(q--) {
        ll l, r;
        cin >> l >> r;
        
        cout << (l <= odd_if ? "YES" : "NO") << nl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -