#include <bits/stdc++.h>
using namespace std;
using ll = int;
using pi = pair<int, int>;
using pl = pair<int, int>;
using vi = vector<int>;
using vl = vector<int>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<int, int>>;
#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const ll mxn = 2e5L + 1;
ll n, m, Q;
vpl adj[mxn];
bool vis[mxn] = {};
ll dep[mxn] = {};
struct Query {
ll l, r, idx;
};
inline bool operator<(Query <, Query &rt) {
if(lt.l != rt.l)
return lt.l < rt.l;
return lt.r > rt.r;
}
struct UFDS {
vl sz;
vl lnk;
vl ene;
UFDS(ll N) {
sz = vl(N, 1);
lnk = vl(N);
iota(all(lnk), 0);
ene = vl(N, -1);
}
ll find(ll a) {
if(a == lnk[a]) {
return a;
}
return lnk[a] = find(lnk[a]);
}
bool same(ll a, ll b) {
return find(a) == find(b);
}
ll unite(ll a, ll b) {
a = find(a);
b = find(b);
if(a == b)
return a;
if(sz[a] < sz[b])
swap(a, b);
lnk[b] = a;
sz[a] += sz[b];
return a;
}
bool makeEne(ll a, ll b) {
a = find(a);
b = find(b);
if(a == b) {
return 0;
}
if(ene[a] == b) {
return 1;
}
ll c = ene[a];
ll d = ene[b];
if(d != -1)
a = unite(a, d);
if(c != -1)
b = unite(b, c);
ene[a] = b;
ene[b] = a;
return 1;
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> Q;
pl edge[m + 1];
fur(i, 1, m) {
cin >> edge[i].fr >> edge[i].sc;
}
Query q[Q];
fur(rep, 0, Q - 1) {
cin >> q[rep].l >> q[rep].r;
q[rep].idx = rep;
}
bool ans[Q] = {};
sort(q, q + Q);
fur(i, 0, Q - 1) {
ll j = i;
while(j + 1 < Q && q[j + 1].l == q[i].l) {
++j;
}
bool yes = 0;
UFDS uf(n + 1);
fur(x, 1, q[i].l - 1) {
yes |= !uf.makeEne(edge[x].fr, edge[x].sc);
}
ll cur_r = m;
fur(x, i, j) {
while(cur_r > q[x].r) {
yes |= !uf.makeEne(edge[cur_r].fr, edge[cur_r].sc);
--cur_r;
}
ans[q[x].idx] = yes;
}
i = j;
}
for(auto u : ans) {
cout << (u ? "YES" : "NO") << nl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
17 ms |
5076 KB |
Output is correct |
30 |
Correct |
28 ms |
5072 KB |
Output is correct |
31 |
Correct |
33 ms |
5080 KB |
Output is correct |
32 |
Correct |
26 ms |
5076 KB |
Output is correct |
33 |
Correct |
22 ms |
5072 KB |
Output is correct |
34 |
Correct |
32 ms |
5076 KB |
Output is correct |
35 |
Correct |
33 ms |
5080 KB |
Output is correct |
36 |
Correct |
30 ms |
4948 KB |
Output is correct |
37 |
Correct |
49 ms |
5076 KB |
Output is correct |
38 |
Correct |
52 ms |
5076 KB |
Output is correct |
39 |
Correct |
34 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5068 KB |
Output is correct |
41 |
Correct |
30 ms |
5076 KB |
Output is correct |
42 |
Correct |
30 ms |
4948 KB |
Output is correct |
43 |
Correct |
30 ms |
4948 KB |
Output is correct |
44 |
Correct |
36 ms |
5060 KB |
Output is correct |
45 |
Correct |
43 ms |
5076 KB |
Output is correct |
46 |
Correct |
50 ms |
5076 KB |
Output is correct |
47 |
Correct |
28 ms |
5060 KB |
Output is correct |
48 |
Correct |
29 ms |
4948 KB |
Output is correct |
49 |
Correct |
31 ms |
5076 KB |
Output is correct |
50 |
Correct |
33 ms |
5076 KB |
Output is correct |
51 |
Correct |
24 ms |
5064 KB |
Output is correct |
52 |
Correct |
27 ms |
5068 KB |
Output is correct |
53 |
Correct |
32 ms |
5076 KB |
Output is correct |
54 |
Correct |
37 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
92 ms |
10296 KB |
Output is correct |
4 |
Correct |
87 ms |
11476 KB |
Output is correct |
5 |
Correct |
87 ms |
11216 KB |
Output is correct |
6 |
Correct |
80 ms |
10264 KB |
Output is correct |
7 |
Correct |
81 ms |
10288 KB |
Output is correct |
8 |
Correct |
75 ms |
9836 KB |
Output is correct |
9 |
Correct |
87 ms |
10196 KB |
Output is correct |
10 |
Correct |
91 ms |
11440 KB |
Output is correct |
11 |
Correct |
83 ms |
10196 KB |
Output is correct |
12 |
Correct |
96 ms |
11348 KB |
Output is correct |
13 |
Correct |
85 ms |
9792 KB |
Output is correct |
14 |
Correct |
104 ms |
9768 KB |
Output is correct |
15 |
Correct |
82 ms |
10672 KB |
Output is correct |
16 |
Correct |
85 ms |
11412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
92 ms |
10296 KB |
Output is correct |
30 |
Correct |
87 ms |
11476 KB |
Output is correct |
31 |
Correct |
87 ms |
11216 KB |
Output is correct |
32 |
Correct |
80 ms |
10264 KB |
Output is correct |
33 |
Correct |
81 ms |
10288 KB |
Output is correct |
34 |
Correct |
75 ms |
9836 KB |
Output is correct |
35 |
Correct |
87 ms |
10196 KB |
Output is correct |
36 |
Correct |
91 ms |
11440 KB |
Output is correct |
37 |
Correct |
83 ms |
10196 KB |
Output is correct |
38 |
Correct |
96 ms |
11348 KB |
Output is correct |
39 |
Correct |
85 ms |
9792 KB |
Output is correct |
40 |
Correct |
104 ms |
9768 KB |
Output is correct |
41 |
Correct |
82 ms |
10672 KB |
Output is correct |
42 |
Correct |
85 ms |
11412 KB |
Output is correct |
43 |
Correct |
852 ms |
10440 KB |
Output is correct |
44 |
Correct |
1450 ms |
11844 KB |
Output is correct |
45 |
Correct |
1460 ms |
11704 KB |
Output is correct |
46 |
Correct |
1133 ms |
10520 KB |
Output is correct |
47 |
Correct |
1368 ms |
10512 KB |
Output is correct |
48 |
Correct |
1325 ms |
10616 KB |
Output is correct |
49 |
Execution timed out |
2065 ms |
11804 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
17 ms |
5076 KB |
Output is correct |
30 |
Correct |
28 ms |
5072 KB |
Output is correct |
31 |
Correct |
33 ms |
5080 KB |
Output is correct |
32 |
Correct |
26 ms |
5076 KB |
Output is correct |
33 |
Correct |
22 ms |
5072 KB |
Output is correct |
34 |
Correct |
32 ms |
5076 KB |
Output is correct |
35 |
Correct |
33 ms |
5080 KB |
Output is correct |
36 |
Correct |
30 ms |
4948 KB |
Output is correct |
37 |
Correct |
49 ms |
5076 KB |
Output is correct |
38 |
Correct |
52 ms |
5076 KB |
Output is correct |
39 |
Correct |
34 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5068 KB |
Output is correct |
41 |
Correct |
30 ms |
5076 KB |
Output is correct |
42 |
Correct |
30 ms |
4948 KB |
Output is correct |
43 |
Correct |
30 ms |
4948 KB |
Output is correct |
44 |
Correct |
36 ms |
5060 KB |
Output is correct |
45 |
Correct |
43 ms |
5076 KB |
Output is correct |
46 |
Correct |
50 ms |
5076 KB |
Output is correct |
47 |
Correct |
28 ms |
5060 KB |
Output is correct |
48 |
Correct |
29 ms |
4948 KB |
Output is correct |
49 |
Correct |
31 ms |
5076 KB |
Output is correct |
50 |
Correct |
33 ms |
5076 KB |
Output is correct |
51 |
Correct |
24 ms |
5064 KB |
Output is correct |
52 |
Correct |
27 ms |
5068 KB |
Output is correct |
53 |
Correct |
32 ms |
5076 KB |
Output is correct |
54 |
Correct |
37 ms |
5076 KB |
Output is correct |
55 |
Execution timed out |
2070 ms |
7972 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
17 ms |
5076 KB |
Output is correct |
30 |
Correct |
28 ms |
5072 KB |
Output is correct |
31 |
Correct |
33 ms |
5080 KB |
Output is correct |
32 |
Correct |
26 ms |
5076 KB |
Output is correct |
33 |
Correct |
22 ms |
5072 KB |
Output is correct |
34 |
Correct |
32 ms |
5076 KB |
Output is correct |
35 |
Correct |
33 ms |
5080 KB |
Output is correct |
36 |
Correct |
30 ms |
4948 KB |
Output is correct |
37 |
Correct |
49 ms |
5076 KB |
Output is correct |
38 |
Correct |
52 ms |
5076 KB |
Output is correct |
39 |
Correct |
34 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5068 KB |
Output is correct |
41 |
Correct |
30 ms |
5076 KB |
Output is correct |
42 |
Correct |
30 ms |
4948 KB |
Output is correct |
43 |
Correct |
30 ms |
4948 KB |
Output is correct |
44 |
Correct |
36 ms |
5060 KB |
Output is correct |
45 |
Correct |
43 ms |
5076 KB |
Output is correct |
46 |
Correct |
50 ms |
5076 KB |
Output is correct |
47 |
Correct |
28 ms |
5060 KB |
Output is correct |
48 |
Correct |
29 ms |
4948 KB |
Output is correct |
49 |
Correct |
31 ms |
5076 KB |
Output is correct |
50 |
Correct |
33 ms |
5076 KB |
Output is correct |
51 |
Correct |
24 ms |
5064 KB |
Output is correct |
52 |
Correct |
27 ms |
5068 KB |
Output is correct |
53 |
Correct |
32 ms |
5076 KB |
Output is correct |
54 |
Correct |
37 ms |
5076 KB |
Output is correct |
55 |
Correct |
92 ms |
10296 KB |
Output is correct |
56 |
Correct |
87 ms |
11476 KB |
Output is correct |
57 |
Correct |
87 ms |
11216 KB |
Output is correct |
58 |
Correct |
80 ms |
10264 KB |
Output is correct |
59 |
Correct |
81 ms |
10288 KB |
Output is correct |
60 |
Correct |
75 ms |
9836 KB |
Output is correct |
61 |
Correct |
87 ms |
10196 KB |
Output is correct |
62 |
Correct |
91 ms |
11440 KB |
Output is correct |
63 |
Correct |
83 ms |
10196 KB |
Output is correct |
64 |
Correct |
96 ms |
11348 KB |
Output is correct |
65 |
Correct |
85 ms |
9792 KB |
Output is correct |
66 |
Correct |
104 ms |
9768 KB |
Output is correct |
67 |
Correct |
82 ms |
10672 KB |
Output is correct |
68 |
Correct |
85 ms |
11412 KB |
Output is correct |
69 |
Correct |
852 ms |
10440 KB |
Output is correct |
70 |
Correct |
1450 ms |
11844 KB |
Output is correct |
71 |
Correct |
1460 ms |
11704 KB |
Output is correct |
72 |
Correct |
1133 ms |
10520 KB |
Output is correct |
73 |
Correct |
1368 ms |
10512 KB |
Output is correct |
74 |
Correct |
1325 ms |
10616 KB |
Output is correct |
75 |
Execution timed out |
2065 ms |
11804 KB |
Time limit exceeded |
76 |
Halted |
0 ms |
0 KB |
- |