#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back
struct UFDS {
vi link, sz, len;
int n;
UFDS(int N) {
init(N);
}
void init(int N) {
n = N;
link = vi(n);
iota(all(link), 0);
sz = vi(n, 1);
len = vi(n, 0);
}
pi find(ll x) {
if(link[x] == x)
return {x, 0};
pi val = find(link[x]);
link[x] = val.fr;
len[x] = (len[x] + val.sc) % 2;
return {link[x], len[x]};
}
void unite(ll a, ll b) {
pi A = find(a);
pi B = find(b);
if(A.fr == B.fr) return;
if(sz[A.fr] < sz[B.fr]) swap(A, B);
link[B.fr] = A.fr;
len[B.fr] = (1 + A.sc + B.sc) % 2;
sz[A.fr] += sz[B.fr];
}
bool same(ll a, ll b){
return (find(a) == find(b));
}
};
void solve()
{
ll n, m, q;
cin >> n >> m >> q;
vector<pi> e(m + 1);
FOR(i, 1, m + 1) {
cin >> e[i].fr >> e[i].sc;
}
UFDS uf(n + 1);
uf.init(n + 1);
while(q--) {
uf.init(n + 1);
int l, r;
cin >> l >> r;
bool cyc = false;
FOR(i, 1, m + 1) {
if(l <= i && i <= r) continue;
if(uf.same(e[i].fr, e[i].sc)) {
pi A = uf.find(e[i].fr);
pi B = uf.find(e[i].sc);
if(A.sc == B.sc) {
cyc = true;
break;
}
} else {
uf.unite(e[i].fr, e[i].sc);
}
}
cout << (cyc ? "YES" : "NO") << nl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
224 KB |
Output is correct |
29 |
Correct |
37 ms |
408 KB |
Output is correct |
30 |
Correct |
36 ms |
408 KB |
Output is correct |
31 |
Correct |
32 ms |
468 KB |
Output is correct |
32 |
Correct |
19 ms |
388 KB |
Output is correct |
33 |
Correct |
12 ms |
372 KB |
Output is correct |
34 |
Correct |
30 ms |
416 KB |
Output is correct |
35 |
Correct |
47 ms |
408 KB |
Output is correct |
36 |
Correct |
35 ms |
340 KB |
Output is correct |
37 |
Correct |
64 ms |
436 KB |
Output is correct |
38 |
Correct |
74 ms |
412 KB |
Output is correct |
39 |
Correct |
51 ms |
412 KB |
Output is correct |
40 |
Correct |
28 ms |
340 KB |
Output is correct |
41 |
Correct |
28 ms |
340 KB |
Output is correct |
42 |
Correct |
28 ms |
340 KB |
Output is correct |
43 |
Correct |
32 ms |
368 KB |
Output is correct |
44 |
Correct |
35 ms |
380 KB |
Output is correct |
45 |
Correct |
35 ms |
396 KB |
Output is correct |
46 |
Correct |
38 ms |
340 KB |
Output is correct |
47 |
Correct |
31 ms |
492 KB |
Output is correct |
48 |
Correct |
32 ms |
380 KB |
Output is correct |
49 |
Correct |
34 ms |
400 KB |
Output is correct |
50 |
Correct |
37 ms |
408 KB |
Output is correct |
51 |
Correct |
29 ms |
372 KB |
Output is correct |
52 |
Correct |
30 ms |
384 KB |
Output is correct |
53 |
Correct |
33 ms |
396 KB |
Output is correct |
54 |
Correct |
41 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2064 ms |
6580 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
224 KB |
Output is correct |
29 |
Execution timed out |
2064 ms |
6580 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
224 KB |
Output is correct |
29 |
Correct |
37 ms |
408 KB |
Output is correct |
30 |
Correct |
36 ms |
408 KB |
Output is correct |
31 |
Correct |
32 ms |
468 KB |
Output is correct |
32 |
Correct |
19 ms |
388 KB |
Output is correct |
33 |
Correct |
12 ms |
372 KB |
Output is correct |
34 |
Correct |
30 ms |
416 KB |
Output is correct |
35 |
Correct |
47 ms |
408 KB |
Output is correct |
36 |
Correct |
35 ms |
340 KB |
Output is correct |
37 |
Correct |
64 ms |
436 KB |
Output is correct |
38 |
Correct |
74 ms |
412 KB |
Output is correct |
39 |
Correct |
51 ms |
412 KB |
Output is correct |
40 |
Correct |
28 ms |
340 KB |
Output is correct |
41 |
Correct |
28 ms |
340 KB |
Output is correct |
42 |
Correct |
28 ms |
340 KB |
Output is correct |
43 |
Correct |
32 ms |
368 KB |
Output is correct |
44 |
Correct |
35 ms |
380 KB |
Output is correct |
45 |
Correct |
35 ms |
396 KB |
Output is correct |
46 |
Correct |
38 ms |
340 KB |
Output is correct |
47 |
Correct |
31 ms |
492 KB |
Output is correct |
48 |
Correct |
32 ms |
380 KB |
Output is correct |
49 |
Correct |
34 ms |
400 KB |
Output is correct |
50 |
Correct |
37 ms |
408 KB |
Output is correct |
51 |
Correct |
29 ms |
372 KB |
Output is correct |
52 |
Correct |
30 ms |
384 KB |
Output is correct |
53 |
Correct |
33 ms |
396 KB |
Output is correct |
54 |
Correct |
41 ms |
408 KB |
Output is correct |
55 |
Execution timed out |
2067 ms |
6596 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
224 KB |
Output is correct |
29 |
Correct |
37 ms |
408 KB |
Output is correct |
30 |
Correct |
36 ms |
408 KB |
Output is correct |
31 |
Correct |
32 ms |
468 KB |
Output is correct |
32 |
Correct |
19 ms |
388 KB |
Output is correct |
33 |
Correct |
12 ms |
372 KB |
Output is correct |
34 |
Correct |
30 ms |
416 KB |
Output is correct |
35 |
Correct |
47 ms |
408 KB |
Output is correct |
36 |
Correct |
35 ms |
340 KB |
Output is correct |
37 |
Correct |
64 ms |
436 KB |
Output is correct |
38 |
Correct |
74 ms |
412 KB |
Output is correct |
39 |
Correct |
51 ms |
412 KB |
Output is correct |
40 |
Correct |
28 ms |
340 KB |
Output is correct |
41 |
Correct |
28 ms |
340 KB |
Output is correct |
42 |
Correct |
28 ms |
340 KB |
Output is correct |
43 |
Correct |
32 ms |
368 KB |
Output is correct |
44 |
Correct |
35 ms |
380 KB |
Output is correct |
45 |
Correct |
35 ms |
396 KB |
Output is correct |
46 |
Correct |
38 ms |
340 KB |
Output is correct |
47 |
Correct |
31 ms |
492 KB |
Output is correct |
48 |
Correct |
32 ms |
380 KB |
Output is correct |
49 |
Correct |
34 ms |
400 KB |
Output is correct |
50 |
Correct |
37 ms |
408 KB |
Output is correct |
51 |
Correct |
29 ms |
372 KB |
Output is correct |
52 |
Correct |
30 ms |
384 KB |
Output is correct |
53 |
Correct |
33 ms |
396 KB |
Output is correct |
54 |
Correct |
41 ms |
408 KB |
Output is correct |
55 |
Execution timed out |
2064 ms |
6580 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |