#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; }
constexpr int nax = 200200;
vector<pair<int,int>> adj[nax];
int color[nax];
pair<int,int> stk[nax];
int p = 0;
vector<bool> trova_cicli(int N, int M, int Q, vector<int> A, vector<int> B, vector<int> L, vector<int> R) {
vector<bool> ans(Q);
for (int i = 0; i < M; i++) {
adj[A[i]].emplace_back(B[i],i);
adj[B[i]].emplace_back(A[i],i);
}
for (int i = 0; i < Q; i++) {
memset(color,-1,4 * N);
int l = L[i], r = R[i];
for (int current_node = 0; current_node < N && !ans[i]; current_node++) if (color[current_node] == -1) {
p = 0;
stk[p] = {current_node,0};
color[current_node] = 0;
while(p != -1) {
auto &[node,idx_adj] = stk[p];
// cout << node << " " << idx_adj << endl;
while(idx_adj < adj[node].size() && (l <= adj[node][idx_adj].second && adj[node][idx_adj].second < r))
idx_adj++;
if (idx_adj == adj[node].size()) {
p--;
continue;
}
int &other_node = adj[node][idx_adj].first;
if (color[other_node] == color[node]) {
ans[i] = 1;
break;
}
if (color[other_node] != -1) {
idx_adj++;
continue;
}
color[other_node] = color[node] ^ 1;
stk[++p] = {other_node,0};
}
}
}
return ans;
}
int main() {
int N,M,Q;
cin >> N >> M >> Q;
vector<int> A(M),B(M),L(Q),R(Q);
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i];
--A[i],--B[i];
}
for (int i = 0; i < Q; i++) {
cin >> L[i] >> R[i];
--L[i];
}
auto res = trova_cicli(N,M,Q,A,B,L,R);
for (int i = 0; i < Q; i++)
cout << (res[i] ? "YES" : "NO") << "\n";
}
Compilation message
Joker.cpp: In function 'std::vector<bool> trova_cicli(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
Joker.cpp:31:31: warning: comparison of integer expressions of different signedness: 'std::tuple_element<1, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(idx_adj < adj[node].size() && (l <= adj[node][idx_adj].second && adj[node][idx_adj].second < r))
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
Joker.cpp:33:29: warning: comparison of integer expressions of different signedness: 'std::tuple_element<1, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if (idx_adj == adj[node].size()) {
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Correct |
2 ms |
7248 KB |
Output is correct |
4 |
Correct |
3 ms |
7248 KB |
Output is correct |
5 |
Correct |
3 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
7248 KB |
Output is correct |
7 |
Correct |
3 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
7248 KB |
Output is correct |
9 |
Correct |
3 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
3 ms |
7332 KB |
Output is correct |
13 |
Correct |
3 ms |
7248 KB |
Output is correct |
14 |
Correct |
3 ms |
7248 KB |
Output is correct |
15 |
Correct |
3 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
3 ms |
7492 KB |
Output is correct |
18 |
Correct |
3 ms |
7248 KB |
Output is correct |
19 |
Correct |
3 ms |
7248 KB |
Output is correct |
20 |
Correct |
3 ms |
7248 KB |
Output is correct |
21 |
Correct |
3 ms |
7156 KB |
Output is correct |
22 |
Correct |
3 ms |
7248 KB |
Output is correct |
23 |
Correct |
3 ms |
7248 KB |
Output is correct |
24 |
Correct |
3 ms |
7248 KB |
Output is correct |
25 |
Correct |
3 ms |
7248 KB |
Output is correct |
26 |
Correct |
3 ms |
7248 KB |
Output is correct |
27 |
Correct |
3 ms |
7248 KB |
Output is correct |
28 |
Correct |
3 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Correct |
2 ms |
7248 KB |
Output is correct |
4 |
Correct |
3 ms |
7248 KB |
Output is correct |
5 |
Correct |
3 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
7248 KB |
Output is correct |
7 |
Correct |
3 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
7248 KB |
Output is correct |
9 |
Correct |
3 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
3 ms |
7332 KB |
Output is correct |
13 |
Correct |
3 ms |
7248 KB |
Output is correct |
14 |
Correct |
3 ms |
7248 KB |
Output is correct |
15 |
Correct |
3 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
3 ms |
7492 KB |
Output is correct |
18 |
Correct |
3 ms |
7248 KB |
Output is correct |
19 |
Correct |
3 ms |
7248 KB |
Output is correct |
20 |
Correct |
3 ms |
7248 KB |
Output is correct |
21 |
Correct |
3 ms |
7156 KB |
Output is correct |
22 |
Correct |
3 ms |
7248 KB |
Output is correct |
23 |
Correct |
3 ms |
7248 KB |
Output is correct |
24 |
Correct |
3 ms |
7248 KB |
Output is correct |
25 |
Correct |
3 ms |
7248 KB |
Output is correct |
26 |
Correct |
3 ms |
7248 KB |
Output is correct |
27 |
Correct |
3 ms |
7248 KB |
Output is correct |
28 |
Correct |
3 ms |
7248 KB |
Output is correct |
29 |
Correct |
62 ms |
7436 KB |
Output is correct |
30 |
Correct |
47 ms |
7248 KB |
Output is correct |
31 |
Correct |
32 ms |
7248 KB |
Output is correct |
32 |
Correct |
17 ms |
7416 KB |
Output is correct |
33 |
Correct |
8 ms |
7332 KB |
Output is correct |
34 |
Correct |
28 ms |
7248 KB |
Output is correct |
35 |
Correct |
49 ms |
7248 KB |
Output is correct |
36 |
Correct |
17 ms |
7504 KB |
Output is correct |
37 |
Correct |
63 ms |
7248 KB |
Output is correct |
38 |
Correct |
83 ms |
7248 KB |
Output is correct |
39 |
Correct |
43 ms |
7248 KB |
Output is correct |
40 |
Correct |
18 ms |
7248 KB |
Output is correct |
41 |
Correct |
18 ms |
7420 KB |
Output is correct |
42 |
Correct |
17 ms |
7248 KB |
Output is correct |
43 |
Correct |
7 ms |
7488 KB |
Output is correct |
44 |
Correct |
6 ms |
7248 KB |
Output is correct |
45 |
Correct |
10 ms |
7248 KB |
Output is correct |
46 |
Correct |
12 ms |
7248 KB |
Output is correct |
47 |
Correct |
19 ms |
7480 KB |
Output is correct |
48 |
Correct |
21 ms |
7332 KB |
Output is correct |
49 |
Correct |
31 ms |
7248 KB |
Output is correct |
50 |
Correct |
37 ms |
7248 KB |
Output is correct |
51 |
Correct |
22 ms |
7248 KB |
Output is correct |
52 |
Correct |
26 ms |
7416 KB |
Output is correct |
53 |
Correct |
33 ms |
7248 KB |
Output is correct |
54 |
Correct |
46 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Execution timed out |
2070 ms |
22344 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Correct |
2 ms |
7248 KB |
Output is correct |
4 |
Correct |
3 ms |
7248 KB |
Output is correct |
5 |
Correct |
3 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
7248 KB |
Output is correct |
7 |
Correct |
3 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
7248 KB |
Output is correct |
9 |
Correct |
3 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
3 ms |
7332 KB |
Output is correct |
13 |
Correct |
3 ms |
7248 KB |
Output is correct |
14 |
Correct |
3 ms |
7248 KB |
Output is correct |
15 |
Correct |
3 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
3 ms |
7492 KB |
Output is correct |
18 |
Correct |
3 ms |
7248 KB |
Output is correct |
19 |
Correct |
3 ms |
7248 KB |
Output is correct |
20 |
Correct |
3 ms |
7248 KB |
Output is correct |
21 |
Correct |
3 ms |
7156 KB |
Output is correct |
22 |
Correct |
3 ms |
7248 KB |
Output is correct |
23 |
Correct |
3 ms |
7248 KB |
Output is correct |
24 |
Correct |
3 ms |
7248 KB |
Output is correct |
25 |
Correct |
3 ms |
7248 KB |
Output is correct |
26 |
Correct |
3 ms |
7248 KB |
Output is correct |
27 |
Correct |
3 ms |
7248 KB |
Output is correct |
28 |
Correct |
3 ms |
7248 KB |
Output is correct |
29 |
Execution timed out |
2070 ms |
22344 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Correct |
2 ms |
7248 KB |
Output is correct |
4 |
Correct |
3 ms |
7248 KB |
Output is correct |
5 |
Correct |
3 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
7248 KB |
Output is correct |
7 |
Correct |
3 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
7248 KB |
Output is correct |
9 |
Correct |
3 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
3 ms |
7332 KB |
Output is correct |
13 |
Correct |
3 ms |
7248 KB |
Output is correct |
14 |
Correct |
3 ms |
7248 KB |
Output is correct |
15 |
Correct |
3 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
3 ms |
7492 KB |
Output is correct |
18 |
Correct |
3 ms |
7248 KB |
Output is correct |
19 |
Correct |
3 ms |
7248 KB |
Output is correct |
20 |
Correct |
3 ms |
7248 KB |
Output is correct |
21 |
Correct |
3 ms |
7156 KB |
Output is correct |
22 |
Correct |
3 ms |
7248 KB |
Output is correct |
23 |
Correct |
3 ms |
7248 KB |
Output is correct |
24 |
Correct |
3 ms |
7248 KB |
Output is correct |
25 |
Correct |
3 ms |
7248 KB |
Output is correct |
26 |
Correct |
3 ms |
7248 KB |
Output is correct |
27 |
Correct |
3 ms |
7248 KB |
Output is correct |
28 |
Correct |
3 ms |
7248 KB |
Output is correct |
29 |
Correct |
62 ms |
7436 KB |
Output is correct |
30 |
Correct |
47 ms |
7248 KB |
Output is correct |
31 |
Correct |
32 ms |
7248 KB |
Output is correct |
32 |
Correct |
17 ms |
7416 KB |
Output is correct |
33 |
Correct |
8 ms |
7332 KB |
Output is correct |
34 |
Correct |
28 ms |
7248 KB |
Output is correct |
35 |
Correct |
49 ms |
7248 KB |
Output is correct |
36 |
Correct |
17 ms |
7504 KB |
Output is correct |
37 |
Correct |
63 ms |
7248 KB |
Output is correct |
38 |
Correct |
83 ms |
7248 KB |
Output is correct |
39 |
Correct |
43 ms |
7248 KB |
Output is correct |
40 |
Correct |
18 ms |
7248 KB |
Output is correct |
41 |
Correct |
18 ms |
7420 KB |
Output is correct |
42 |
Correct |
17 ms |
7248 KB |
Output is correct |
43 |
Correct |
7 ms |
7488 KB |
Output is correct |
44 |
Correct |
6 ms |
7248 KB |
Output is correct |
45 |
Correct |
10 ms |
7248 KB |
Output is correct |
46 |
Correct |
12 ms |
7248 KB |
Output is correct |
47 |
Correct |
19 ms |
7480 KB |
Output is correct |
48 |
Correct |
21 ms |
7332 KB |
Output is correct |
49 |
Correct |
31 ms |
7248 KB |
Output is correct |
50 |
Correct |
37 ms |
7248 KB |
Output is correct |
51 |
Correct |
22 ms |
7248 KB |
Output is correct |
52 |
Correct |
26 ms |
7416 KB |
Output is correct |
53 |
Correct |
33 ms |
7248 KB |
Output is correct |
54 |
Correct |
46 ms |
7248 KB |
Output is correct |
55 |
Execution timed out |
2056 ms |
17736 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7248 KB |
Output is correct |
2 |
Correct |
2 ms |
7248 KB |
Output is correct |
3 |
Correct |
2 ms |
7248 KB |
Output is correct |
4 |
Correct |
3 ms |
7248 KB |
Output is correct |
5 |
Correct |
3 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
7248 KB |
Output is correct |
7 |
Correct |
3 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
7248 KB |
Output is correct |
9 |
Correct |
3 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
3 ms |
7332 KB |
Output is correct |
13 |
Correct |
3 ms |
7248 KB |
Output is correct |
14 |
Correct |
3 ms |
7248 KB |
Output is correct |
15 |
Correct |
3 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
3 ms |
7492 KB |
Output is correct |
18 |
Correct |
3 ms |
7248 KB |
Output is correct |
19 |
Correct |
3 ms |
7248 KB |
Output is correct |
20 |
Correct |
3 ms |
7248 KB |
Output is correct |
21 |
Correct |
3 ms |
7156 KB |
Output is correct |
22 |
Correct |
3 ms |
7248 KB |
Output is correct |
23 |
Correct |
3 ms |
7248 KB |
Output is correct |
24 |
Correct |
3 ms |
7248 KB |
Output is correct |
25 |
Correct |
3 ms |
7248 KB |
Output is correct |
26 |
Correct |
3 ms |
7248 KB |
Output is correct |
27 |
Correct |
3 ms |
7248 KB |
Output is correct |
28 |
Correct |
3 ms |
7248 KB |
Output is correct |
29 |
Correct |
62 ms |
7436 KB |
Output is correct |
30 |
Correct |
47 ms |
7248 KB |
Output is correct |
31 |
Correct |
32 ms |
7248 KB |
Output is correct |
32 |
Correct |
17 ms |
7416 KB |
Output is correct |
33 |
Correct |
8 ms |
7332 KB |
Output is correct |
34 |
Correct |
28 ms |
7248 KB |
Output is correct |
35 |
Correct |
49 ms |
7248 KB |
Output is correct |
36 |
Correct |
17 ms |
7504 KB |
Output is correct |
37 |
Correct |
63 ms |
7248 KB |
Output is correct |
38 |
Correct |
83 ms |
7248 KB |
Output is correct |
39 |
Correct |
43 ms |
7248 KB |
Output is correct |
40 |
Correct |
18 ms |
7248 KB |
Output is correct |
41 |
Correct |
18 ms |
7420 KB |
Output is correct |
42 |
Correct |
17 ms |
7248 KB |
Output is correct |
43 |
Correct |
7 ms |
7488 KB |
Output is correct |
44 |
Correct |
6 ms |
7248 KB |
Output is correct |
45 |
Correct |
10 ms |
7248 KB |
Output is correct |
46 |
Correct |
12 ms |
7248 KB |
Output is correct |
47 |
Correct |
19 ms |
7480 KB |
Output is correct |
48 |
Correct |
21 ms |
7332 KB |
Output is correct |
49 |
Correct |
31 ms |
7248 KB |
Output is correct |
50 |
Correct |
37 ms |
7248 KB |
Output is correct |
51 |
Correct |
22 ms |
7248 KB |
Output is correct |
52 |
Correct |
26 ms |
7416 KB |
Output is correct |
53 |
Correct |
33 ms |
7248 KB |
Output is correct |
54 |
Correct |
46 ms |
7248 KB |
Output is correct |
55 |
Execution timed out |
2070 ms |
22344 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |