#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
int n,m,q;
struct edge {
int a,b;
} egs[MAX];
vector<pii> G[MAX];
struct query{
int l,r,id;
}qry[MAX];
int p[MAX];
int sz[MAX];
int rev[MAX];
void init() {
for (int i=1;i<=n;i++) {
p[i]=i;
sz[i]=1;
rev[i]=0;
}
}
pii get(int a) {
if (p[a]==a) return {a,0};
else {
auto [fa,c]=get(p[a]);
return {fa,c^rev[a]};
}
}
int main() {
speed;
cin>>n>>m>>q;
for (int i=1;i<=m;i++) {
int a,b;
cin>>a>>b;
egs[i]={a,b};
G[a].emplace_back(b,i);
G[b].emplace_back(a,i);
}
init();
int ans=0;
for (int i=m;i>=1;i--) {
edge eg=egs[i];
auto [pa,ca]=get(eg.a);
auto [pb,cb]=get(eg.b);
// cout<<i<<" i\n";
// cout<<eg.a<<" "<<pa<<" "<<ca<<"\n";
// cout<<eg.b<<" "<<pb<<" "<<cb<<"\n";
if (pa==pb) {
if (ca==cb) {
ans=i;
break;
}
} else {
if (sz[pa]<sz[pb]) {
swap(pa,pb);
}
p[pb]=pa;
sz[pa]+=sz[pb];
rev[pb]=(ca==cb);
}
}
// cout<<ans<<" ans\n";
for (int i=1;i<=q;i++) {
cin>>qry[i].l>>qry[i].r;
qry[i].id=i;
if (qry[i].r>=ans) cout<<"NO\n";
else cout<<"YES\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
69 ms |
20596 KB |
Output is correct |
4 |
Correct |
75 ms |
22844 KB |
Output is correct |
5 |
Correct |
77 ms |
23464 KB |
Output is correct |
6 |
Correct |
75 ms |
22408 KB |
Output is correct |
7 |
Correct |
72 ms |
22352 KB |
Output is correct |
8 |
Correct |
67 ms |
21076 KB |
Output is correct |
9 |
Correct |
70 ms |
21648 KB |
Output is correct |
10 |
Correct |
75 ms |
22608 KB |
Output is correct |
11 |
Correct |
72 ms |
21968 KB |
Output is correct |
12 |
Correct |
77 ms |
22732 KB |
Output is correct |
13 |
Correct |
83 ms |
21160 KB |
Output is correct |
14 |
Correct |
77 ms |
21660 KB |
Output is correct |
15 |
Correct |
78 ms |
22500 KB |
Output is correct |
16 |
Correct |
88 ms |
23120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |