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;
vector<int> a[2000];
map<pair<int, int>, int> t;
int l, r, c, b[2000], d[2000];
void dfs(int u, int p){
if(c) return;
for(int v : a[u]){
if(v == p || (t[{min(u, v), max(u, v)}] >= l && t[{min(u, v), max(u, v)}] <= r) || c) continue;
if(b[v] && (d[v] == d[u])) {c = 1; continue;}
else if(b[v]) continue;
b[v] = 1;
d[v] = (d[u]+1)%2;
dfs(v, u);
}
}
int main(){
int n, m, q;
cin >> n >> m >> q;
for(int i = 0; i < m; i++){
int x, y;
cin >> x >> y;
x--; y--;
t[{min(x, y), max(x, y)}] = i;
a[x].push_back(y);
a[y].push_back(x);
}
while(q--){
cin >> l >> r;
l--; r--;
for(int i = 0; i < n; i++) b[i] = 0;
c = 0;
for(int i = 0; i < n; i++){
if(c || b[i]) continue;
b[i] = 1;
dfs(i, -1);
}
if(c) cout << "YES\n";
else cout << "NO\n";
}
}
# | 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... |