This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int maxn = 2e5 + 5;
int N, M, Q, ok = 0;
int vis[maxn];
vector<pair<int, int> > G[maxn];
void dfs(int u, int par, int col, int l, int r) {
vis[u] = col;
for (auto node : G[u]) {
if (node.fi == par || (l <= node.se && node.se <= r)) continue;
if (vis[node.fi] == vis[u]) ok = 1;
if (!vis[node.fi])
dfs(node.fi, u, 3 - col, l, r);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N >> M >> Q;
rep(i, 1, M) {
int u, v;
cin >> u >> v;
G[u].push_back(mp(v, i));
G[v].push_back(mp(u, i));
}
while (Q--) {
int l, r;
cin >> l >> r;
ok = 0;
rep(i, 1, N) vis[i] = 0;
rep(i, 1, N) if (!vis[i])
dfs(i, 0, 1, l, r);
cout << (ok ? "YES\n" : "NO\n");
}
return 0;
}
# | 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... |