#ifndef local
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#endif
#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;
using ll = int;
using pll = pair<ll,ll>;
using str = string;
using ld = long double;
using hash_map =gp_hash_table<int, int>;
using hash_set= gp_hash_table <int, null_type>;
auto sd = std::chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(sd);
typedef tree<ll, null_type, less<>, rb_tree_tag,
        tree_order_statistics_node_update> ord_set;
ll inv(ll c){
    if (c==1)return 2;
    return 1;
}
void dfs(ll v, vector<vector<ll>>&g, vector<ll>&col, ll c, bool &is){
    col[v] = c;
    for (auto u : g[v]){
        if (!col[u]){
            dfs(u, g, col, inv(c),is);
        }
        else if (c == col[u]){
            is = false;
            return;
        }
    }
}
void solve1() {
    ll n;
    cin >> n;
    ll m;
    cin >> m; ll q; cin >> q;
    vector<pll> edges;
    for (int i =0; i < m; i++){
        int a, b;
        cin>>a>>b;
        a--; b--;
        edges.emplace_back(a, b);
    }
    if (max(n, m)*q <= 50000000ll){
        for (int i = 0; i <q; i++){
            ll l, r;
            cin>>l>>r; l--; r--;
            vector<vector<ll>>g(n);
            for (int j = 0; j<l;j++){
                g[edges[j].first].emplace_back(edges[j].second);
                g[edges[j].second].emplace_back(edges[j].first);
            }
            for (int j = r+1; j< m; j++){
                g[edges[j].first].emplace_back(edges[j].second);
                g[edges[j].second].emplace_back(edges[j].first);
            }
            vector<int>col(n);
            bool is =true;
            for (int j = 0; j < n; j++){
                if (!col[j]){
                    dfs(j, g, col, 1, is);
                }
            }
            if (!is){
                cout<<"YES\n";
            }
            else {
                cout<<"NO\n";
            }
        }
    }
    else {
        vector<ll> ans(m);
        for (int i = 0; i < min(201, m); i++){
            ll li = i-1;
            ll ri = m;
            while (ri-li>1) {
                ll mi =(li+ri)/2;
                vector<vector<ll>>g(n);
                for (int j = 0; j < i; j++) {
                    g[edges[j].first].emplace_back(edges[j].second);
                    g[edges[j].second].emplace_back(edges[j].first);
                }
                for (int j = mi+1; j< m; j++){
                    g[edges[j].first].emplace_back(edges[j].second);
                    g[edges[j].second].emplace_back(edges[j].first);
                }
                bool is =true;
                vector<ll> col(n);
                for (int j = 0; j < n; j++){
                    if (!col[j]){
                        dfs(j, g, col, 1, is);
                    }
                }
                if (!is) {
                    li = mi;
                }
                else ri = mi;
            }
            ans[i] = li;
        }
        for (int i =0; i < q; i++){
            int l, r;
            cin>>l>>r;
            l--;
            r--;
            if (r<=ans[l]){
                cout<<"YES\n";
            }
            else cout<<"NO\n";
        }
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef local
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    solve1();
#ifdef local
    printf_s("\n%.5f s", (double) clock() / CLOCKS_PER_SEC);
#endif
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |