# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
931440 |
2024-02-21T19:37:34 Z |
qwusha |
Joker (BOI20_joker) |
C++17 |
|
115 ms |
12884 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ll inf = 1e9;
const ld eps = 1e-8;
const ll logs = 32;
#include <cmath>
bool ch = 0;
vector<vector<pair<ll, ll>>> g;
vector<bool> ok;
vector<ll> col;
void dfs(ll v, ll c = 0) {
col[v] = c;
for (auto [u, ind] : g[v]) {
if (!ok[ind]) {
continue;
}
if (col[u] == -1)
dfs(u, 1 - c);
else if (col[u] == col[v])
ch = 1;
}
}
struct dsu {
vector<ll> par, dist, sz;
void init(ll n) {
par.resize(n);
dist.resize(n);
sz.resize(n);
for (ll i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
ll get_par(ll v) {
if (v == par[v])
return v;
ll ans = get_par(par[v]);
dist[v] = (dist[par[v]] + dist[v]) % 2;
par[v] = ans;
return ans;
}
ll get_dist(ll v) {
if (v == par[v])
return 0;
return (dist[v] + get_dist(par[v])) % 2;
}
void union_(ll v, ll u) {
ll nv = get_par(v);
ll nu = get_par(u);
if (nv == nu) {
if (get_dist(v) == get_dist(u))
ch = 1;
return;
}
if (sz[nu] > sz[nv]) {
swap(nv, nu);
swap(u, v);
}
ll uu = get_dist(u), vv = get_dist(v);
dist[nu] = (get_dist(u) + get_dist(v) + 1) % 2;
par[nu] = nv;
sz[nv] += sz[nu];
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, q;
cin >> n >> m >> q;
if (n <= 2000 && m <= 2000 && q <= 2000) {
g.resize(n);
ok.resize(m, 1);
col.resize(n);
for (ll i = 0; i < m; i++) {
ll v, u;
cin >> v >> u;
g[v - 1].push_back({u - 1, i});
g[u - 1].push_back({v - 1, i});
}
for (ll qw = 0; qw < q; qw++) {
ll l, r;
cin >> l >> r;
for (ll i = 0; i < m; i++) {
if (l - 1 <= i && i < r)
ok[i] = 0;
else
ok[i] = 1;
}
for (ll i = 0; i < n; i++) {
col[i] = -1;
}
bool check = 0;
for (ll i = 0; i < n; i++) {
if (col[i] == -1) {
ch = 0;
dfs(i);
if (ch)
check = 1;
}
}
if (check) {
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
}
} else {
vector<pair<ll, ll>> vert(m);
for (ll i = 0; i < m; i++) {
ll v, u;
cin >> v >> u;
vert[i] = {v - 1, u - 1};
}
reverse(vert.begin(), vert.end());
ll val = -1;
dsu dsu;
dsu.init(n);
for (ll i = 0; i < m; i++) {
auto [v, u] = vert[i];
ch = 0;
dsu.union_(v, u);
if (ch) {
val = (m - i);
break;
}
}
//cout << val << endl;
for (ll qw = 0; qw < q; qw++) {
ll l, r;
cin >> l >> r;
if (r < val)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
}
}
Compilation message
Joker.cpp: In member function 'void dsu::union_(ll, ll)':
Joker.cpp:66:12: warning: unused variable 'uu' [-Wunused-variable]
66 | ll uu = get_dist(u), vv = get_dist(v);
| ^~
Joker.cpp:66:30: warning: unused variable 'vv' [-Wunused-variable]
66 | ll uu = get_dist(u), vv = get_dist(v);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
46 ms |
568 KB |
Output is correct |
30 |
Correct |
108 ms |
600 KB |
Output is correct |
31 |
Correct |
104 ms |
604 KB |
Output is correct |
32 |
Correct |
85 ms |
604 KB |
Output is correct |
33 |
Correct |
68 ms |
604 KB |
Output is correct |
34 |
Correct |
112 ms |
600 KB |
Output is correct |
35 |
Correct |
115 ms |
600 KB |
Output is correct |
36 |
Correct |
35 ms |
604 KB |
Output is correct |
37 |
Correct |
62 ms |
600 KB |
Output is correct |
38 |
Correct |
51 ms |
604 KB |
Output is correct |
39 |
Correct |
76 ms |
604 KB |
Output is correct |
40 |
Correct |
72 ms |
600 KB |
Output is correct |
41 |
Correct |
72 ms |
604 KB |
Output is correct |
42 |
Correct |
72 ms |
604 KB |
Output is correct |
43 |
Correct |
57 ms |
600 KB |
Output is correct |
44 |
Correct |
72 ms |
604 KB |
Output is correct |
45 |
Correct |
85 ms |
628 KB |
Output is correct |
46 |
Correct |
91 ms |
636 KB |
Output is correct |
47 |
Correct |
70 ms |
604 KB |
Output is correct |
48 |
Correct |
77 ms |
612 KB |
Output is correct |
49 |
Correct |
92 ms |
600 KB |
Output is correct |
50 |
Correct |
107 ms |
616 KB |
Output is correct |
51 |
Correct |
72 ms |
604 KB |
Output is correct |
52 |
Correct |
84 ms |
612 KB |
Output is correct |
53 |
Correct |
97 ms |
624 KB |
Output is correct |
54 |
Correct |
115 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
56 ms |
6484 KB |
Output is correct |
4 |
Correct |
58 ms |
8784 KB |
Output is correct |
5 |
Correct |
56 ms |
8272 KB |
Output is correct |
6 |
Correct |
57 ms |
10424 KB |
Output is correct |
7 |
Correct |
57 ms |
10580 KB |
Output is correct |
8 |
Correct |
60 ms |
9040 KB |
Output is correct |
9 |
Correct |
55 ms |
10008 KB |
Output is correct |
10 |
Correct |
60 ms |
12372 KB |
Output is correct |
11 |
Correct |
58 ms |
10464 KB |
Output is correct |
12 |
Correct |
60 ms |
12300 KB |
Output is correct |
13 |
Correct |
56 ms |
8528 KB |
Output is correct |
14 |
Correct |
57 ms |
9556 KB |
Output is correct |
15 |
Correct |
59 ms |
11516 KB |
Output is correct |
16 |
Correct |
60 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
56 ms |
6484 KB |
Output is correct |
30 |
Correct |
58 ms |
8784 KB |
Output is correct |
31 |
Correct |
56 ms |
8272 KB |
Output is correct |
32 |
Correct |
57 ms |
10424 KB |
Output is correct |
33 |
Correct |
57 ms |
10580 KB |
Output is correct |
34 |
Correct |
60 ms |
9040 KB |
Output is correct |
35 |
Correct |
55 ms |
10008 KB |
Output is correct |
36 |
Correct |
60 ms |
12372 KB |
Output is correct |
37 |
Correct |
58 ms |
10464 KB |
Output is correct |
38 |
Correct |
60 ms |
12300 KB |
Output is correct |
39 |
Correct |
56 ms |
8528 KB |
Output is correct |
40 |
Correct |
57 ms |
9556 KB |
Output is correct |
41 |
Correct |
59 ms |
11516 KB |
Output is correct |
42 |
Correct |
60 ms |
12884 KB |
Output is correct |
43 |
Incorrect |
58 ms |
10836 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
46 ms |
568 KB |
Output is correct |
30 |
Correct |
108 ms |
600 KB |
Output is correct |
31 |
Correct |
104 ms |
604 KB |
Output is correct |
32 |
Correct |
85 ms |
604 KB |
Output is correct |
33 |
Correct |
68 ms |
604 KB |
Output is correct |
34 |
Correct |
112 ms |
600 KB |
Output is correct |
35 |
Correct |
115 ms |
600 KB |
Output is correct |
36 |
Correct |
35 ms |
604 KB |
Output is correct |
37 |
Correct |
62 ms |
600 KB |
Output is correct |
38 |
Correct |
51 ms |
604 KB |
Output is correct |
39 |
Correct |
76 ms |
604 KB |
Output is correct |
40 |
Correct |
72 ms |
600 KB |
Output is correct |
41 |
Correct |
72 ms |
604 KB |
Output is correct |
42 |
Correct |
72 ms |
604 KB |
Output is correct |
43 |
Correct |
57 ms |
600 KB |
Output is correct |
44 |
Correct |
72 ms |
604 KB |
Output is correct |
45 |
Correct |
85 ms |
628 KB |
Output is correct |
46 |
Correct |
91 ms |
636 KB |
Output is correct |
47 |
Correct |
70 ms |
604 KB |
Output is correct |
48 |
Correct |
77 ms |
612 KB |
Output is correct |
49 |
Correct |
92 ms |
600 KB |
Output is correct |
50 |
Correct |
107 ms |
616 KB |
Output is correct |
51 |
Correct |
72 ms |
604 KB |
Output is correct |
52 |
Correct |
84 ms |
612 KB |
Output is correct |
53 |
Correct |
97 ms |
624 KB |
Output is correct |
54 |
Correct |
115 ms |
896 KB |
Output is correct |
55 |
Incorrect |
25 ms |
5724 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
46 ms |
568 KB |
Output is correct |
30 |
Correct |
108 ms |
600 KB |
Output is correct |
31 |
Correct |
104 ms |
604 KB |
Output is correct |
32 |
Correct |
85 ms |
604 KB |
Output is correct |
33 |
Correct |
68 ms |
604 KB |
Output is correct |
34 |
Correct |
112 ms |
600 KB |
Output is correct |
35 |
Correct |
115 ms |
600 KB |
Output is correct |
36 |
Correct |
35 ms |
604 KB |
Output is correct |
37 |
Correct |
62 ms |
600 KB |
Output is correct |
38 |
Correct |
51 ms |
604 KB |
Output is correct |
39 |
Correct |
76 ms |
604 KB |
Output is correct |
40 |
Correct |
72 ms |
600 KB |
Output is correct |
41 |
Correct |
72 ms |
604 KB |
Output is correct |
42 |
Correct |
72 ms |
604 KB |
Output is correct |
43 |
Correct |
57 ms |
600 KB |
Output is correct |
44 |
Correct |
72 ms |
604 KB |
Output is correct |
45 |
Correct |
85 ms |
628 KB |
Output is correct |
46 |
Correct |
91 ms |
636 KB |
Output is correct |
47 |
Correct |
70 ms |
604 KB |
Output is correct |
48 |
Correct |
77 ms |
612 KB |
Output is correct |
49 |
Correct |
92 ms |
600 KB |
Output is correct |
50 |
Correct |
107 ms |
616 KB |
Output is correct |
51 |
Correct |
72 ms |
604 KB |
Output is correct |
52 |
Correct |
84 ms |
612 KB |
Output is correct |
53 |
Correct |
97 ms |
624 KB |
Output is correct |
54 |
Correct |
115 ms |
896 KB |
Output is correct |
55 |
Correct |
56 ms |
6484 KB |
Output is correct |
56 |
Correct |
58 ms |
8784 KB |
Output is correct |
57 |
Correct |
56 ms |
8272 KB |
Output is correct |
58 |
Correct |
57 ms |
10424 KB |
Output is correct |
59 |
Correct |
57 ms |
10580 KB |
Output is correct |
60 |
Correct |
60 ms |
9040 KB |
Output is correct |
61 |
Correct |
55 ms |
10008 KB |
Output is correct |
62 |
Correct |
60 ms |
12372 KB |
Output is correct |
63 |
Correct |
58 ms |
10464 KB |
Output is correct |
64 |
Correct |
60 ms |
12300 KB |
Output is correct |
65 |
Correct |
56 ms |
8528 KB |
Output is correct |
66 |
Correct |
57 ms |
9556 KB |
Output is correct |
67 |
Correct |
59 ms |
11516 KB |
Output is correct |
68 |
Correct |
60 ms |
12884 KB |
Output is correct |
69 |
Incorrect |
58 ms |
10836 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |