Submission #726660

#TimeUsernameProblemLanguageResultExecution timeMemory
726660JohannJoker (BOI20_joker)C++14
0 / 100
2061 ms11896 KiB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

int N, M, Q;
vvpii adj;
vpii E;

bool possible_bfs(int l, int r)
{
    vi color(N, -1);
    queue<int> q;
    q.push(0), color[0] = 0;
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (pii e : adj[v])
        {
            if (e.second < l || e.second > r)
            {
                if (color[e.first] == color[v])
                    return true;
                if (color[e.first] == -1)
                {
                    q.push(e.first);
                    color[e.first] = !color[v];
                }
            }
        }
    }
    return false;
}

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

    cin >> N >> M >> Q;
    adj.resize(N);
    E.resize(M);
    for (int i = 0, a, b; i < M; ++i)
    {
        cin >> a >> b;
        --a, --b;
        adj[a].push_back({b, i}), adj[b].push_back({a, i});
        E[i] = {min(a, b), max(a, b)};
    }

    for (int i = 0, l, r; i < Q; ++i)
    {
        cin >> l >> r;
        --l, --r; // [l, r] inclusive is blocked
        if (possible_bfs(l, r))
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...