#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;
#define int long long
#define pb push_back
#define mp make_pair
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
constexpr int N = (int)2e5 + 111;
constexpr int md = (int)2e5 + 111;
mt19937 rnd(time(nullptr));
vector<int> g[N];
bool used[2][N];
bool c[2][N];
bool dfs(int v,int r,int pr = -1){
used[r][v] = true;
c[r][v] = true;
for(auto& to : g[v]){
if(pr == to)
continue;
if(used[r^1][to]){
if(c[r][v]&c[r^1][to])
return true;
if(c[r^1][v]&c[r][to])
return true;
continue;
}
c[r^1][to] = true;
if(dfs(to,r^1,v))
return true;
}
return false;
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
vector<pair<int,int>> edges;
for(int i = 0; i < m; i++){
int a,b;
cin >> a >> b;
edges.pb(mp(a,b));
}
for(int i = 0; i < q; i++){
int l,r;
cin >> l >> r;
for(int j = 0; j <= n; j++){
used[0][j] = false;
used[1][j] = false;
c[0][j] = c[1][j] = 0;
g[j].clear();
}
for(int j = 0; j < l-1; j++){
auto&[a,b] = edges[j];
g[a].pb(b);
g[b].pb(a);
}
for(int j = r; j < m; j++){
auto&[a,b] = edges[j];
g[a].pb(b);
g[b].pb(a);
}
bool ok = false;
for(int j = 1; j <= n; j++){
if(!used[0][j]){
c[0][j] = 1;
if(dfs(j,0)){
cout << "YES\n";
ok = true;
break;
}
}
}
if(!ok){
cout << "NO\n";
}
}
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
// init();
int tests = 1;
// cin >> tests;
for(int test = 1; test <= tests; test++){
// cerr << "test = " << test << "\n";
solve();
}
return 0;
}
/**
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4960 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5028 KB |
Output is correct |
6 |
Correct |
4 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4960 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5028 KB |
Output is correct |
6 |
Correct |
4 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Execution timed out |
2027 ms |
26856 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4960 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5028 KB |
Output is correct |
6 |
Correct |
4 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4960 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5028 KB |
Output is correct |
6 |
Correct |
4 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4960 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5028 KB |
Output is correct |
6 |
Correct |
4 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |