#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))
using namespace std;
mt19937_64 rng(228);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
const int N = 4e5 + 5;
int n, m, q;
ve<pii> e;
int ans[N];
int link[N];
ve<int> g[N];
int root(int x) {
if (link[x] == x) {
return x;
} else {
return link[x] = root(link[x]);
}
}
bool uni(int a, int b) {
a = root(a);
b = root(b);
if (a == b) {
return 0;
}
link[a] = b;
return 1;
}
int dep[N];
int up[N][20];
int tin[N], tout[N], timer;
int vis[N];
ve<pii> ask[N];
void dfs(int v, int p) {
vis[v] = 1;
tin[v] = timer++;
up[v][0] = p;
fr (i, 1, 19) {
up[v][i] = up[up[v][i - 1]][i - 1];
}
fe (to, g[v]) {
if (to == p) continue;
dep[to] = dep[v] + 1;
dfs(to, v);
}
tout[v] = timer;
}
bool isUpper(int a, int b) {
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int getLCA(int a, int b) {
if (isUpper(a, b)) return a;
if (isUpper(b, a)) return b;
rf (i, 19, 0) {
if (up[a][i] && !isUpper(up[a][i], b)) {
a = up[a][i];
}
}
return up[a][0];
}
int getDist(int a, int b) {
int c = getLCA(a, b);
return dep[a] + dep[b] - 2 * dep[c];
}
bool found;
int l, r;
ve<pii> G[N];
void DFS(int v, int p) {
vis[v] = 1;
fe (to, G[v]) {
if (to.fi == p) continue;
if (to.se >= l && to.se <= r) continue;
if (!vis[to.fi]) {
dep[to.fi] = dep[v] + 1;
DFS(to.fi, v);
} else {
if (vis[to.fi] == 2) {
found |= (dep[v] - dep[to.fi]) % 2 == 0;
}
}
}
vis[v] = 2;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> m >> q;
fr (i, 1, m) {
int a, b;
cin >> a >> b;
e.pb({a, b});
G[a].pb({b, i - 1});
G[b].pb({a, i - 1});
}
fr (i, 0, m - 1) {
e.pb(e[i]);
}
fr (i, 1, q) {
cin >> l >> r;
l--;
r--;
// r+1..m-1+l
// found = 0;
// fill(vis + 1, vis + 1 + n, 0);
// fr (v, 1, n) {
// if (!vis[v]) {
// dep[v] = 0;
// DFS(v, 0);
// }
// }
if (l == 0 && r == m - 1) {
ans[i] = 0;
} else {
ask[m - 1 + l].pb({r + 1, i});
}
// if (found) {
// cout << "YES\n";
// } else {
// cout << "NO\n";
// }
}
// return 0;
fr (i, 0, sz(e) - 1) {
if (sz(ask[i])) {
sort(all(ask[i]));
reverse(all(ask[i]));
iota(link, link + n + 1, 0);
fr (j, 1, n) g[j].clear();
rf (j, i, 0) {
if (uni(e[j].fi, e[j].se)) {
g[e[j].fi].pb(e[j].se);
g[e[j].se].pb(e[j].fi);
}
}
fr (v, 1, n) {
fr (p, 0, 19) {
up[v][p] = 0;
}
}
fill(vis + 1, vis + 1 + n, 0);
fr (v, 1, n) {
if (!vis[v]) {
timer = 0;
dep[v] = 0;
dfs(v, 0);
}
}
iota(link, link + n + 1, 0);
bool ok = 0;
int ptr = 0;
rf (j, i, 0) {
if (uni(e[j].fi, e[j].se)) {
} else {
int d = getDist(e[j].fi, e[j].se);
if (d % 2 == 0) {
ok = 1;
}
}
while (ptr < sz(ask[i]) && ask[i][ptr].fi == j) {
ans[ask[i][ptr].se] = ok;
ptr++;
}
}
}
}
fr (i, 1, q) {
if (ans[i]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
16 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28420 KB |
Output is correct |
5 |
Correct |
14 ms |
28512 KB |
Output is correct |
6 |
Correct |
14 ms |
28460 KB |
Output is correct |
7 |
Correct |
16 ms |
28488 KB |
Output is correct |
8 |
Correct |
19 ms |
28552 KB |
Output is correct |
9 |
Correct |
18 ms |
28500 KB |
Output is correct |
10 |
Correct |
21 ms |
28500 KB |
Output is correct |
11 |
Correct |
20 ms |
28596 KB |
Output is correct |
12 |
Correct |
19 ms |
28512 KB |
Output is correct |
13 |
Correct |
18 ms |
28512 KB |
Output is correct |
14 |
Correct |
18 ms |
28540 KB |
Output is correct |
15 |
Correct |
18 ms |
28500 KB |
Output is correct |
16 |
Correct |
18 ms |
28536 KB |
Output is correct |
17 |
Correct |
17 ms |
28500 KB |
Output is correct |
18 |
Correct |
18 ms |
28592 KB |
Output is correct |
19 |
Correct |
18 ms |
28492 KB |
Output is correct |
20 |
Correct |
16 ms |
28576 KB |
Output is correct |
21 |
Correct |
17 ms |
28520 KB |
Output is correct |
22 |
Correct |
20 ms |
28592 KB |
Output is correct |
23 |
Correct |
20 ms |
28572 KB |
Output is correct |
24 |
Correct |
19 ms |
28632 KB |
Output is correct |
25 |
Correct |
21 ms |
28568 KB |
Output is correct |
26 |
Correct |
17 ms |
28520 KB |
Output is correct |
27 |
Correct |
19 ms |
28516 KB |
Output is correct |
28 |
Correct |
19 ms |
28596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
16 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28420 KB |
Output is correct |
5 |
Correct |
14 ms |
28512 KB |
Output is correct |
6 |
Correct |
14 ms |
28460 KB |
Output is correct |
7 |
Correct |
16 ms |
28488 KB |
Output is correct |
8 |
Correct |
19 ms |
28552 KB |
Output is correct |
9 |
Correct |
18 ms |
28500 KB |
Output is correct |
10 |
Correct |
21 ms |
28500 KB |
Output is correct |
11 |
Correct |
20 ms |
28596 KB |
Output is correct |
12 |
Correct |
19 ms |
28512 KB |
Output is correct |
13 |
Correct |
18 ms |
28512 KB |
Output is correct |
14 |
Correct |
18 ms |
28540 KB |
Output is correct |
15 |
Correct |
18 ms |
28500 KB |
Output is correct |
16 |
Correct |
18 ms |
28536 KB |
Output is correct |
17 |
Correct |
17 ms |
28500 KB |
Output is correct |
18 |
Correct |
18 ms |
28592 KB |
Output is correct |
19 |
Correct |
18 ms |
28492 KB |
Output is correct |
20 |
Correct |
16 ms |
28576 KB |
Output is correct |
21 |
Correct |
17 ms |
28520 KB |
Output is correct |
22 |
Correct |
20 ms |
28592 KB |
Output is correct |
23 |
Correct |
20 ms |
28572 KB |
Output is correct |
24 |
Correct |
19 ms |
28632 KB |
Output is correct |
25 |
Correct |
21 ms |
28568 KB |
Output is correct |
26 |
Correct |
17 ms |
28520 KB |
Output is correct |
27 |
Correct |
19 ms |
28516 KB |
Output is correct |
28 |
Correct |
19 ms |
28596 KB |
Output is correct |
29 |
Correct |
225 ms |
28888 KB |
Output is correct |
30 |
Correct |
422 ms |
28964 KB |
Output is correct |
31 |
Correct |
405 ms |
28936 KB |
Output is correct |
32 |
Correct |
302 ms |
28836 KB |
Output is correct |
33 |
Correct |
216 ms |
28792 KB |
Output is correct |
34 |
Correct |
456 ms |
28976 KB |
Output is correct |
35 |
Correct |
443 ms |
29096 KB |
Output is correct |
36 |
Correct |
232 ms |
28876 KB |
Output is correct |
37 |
Correct |
401 ms |
29016 KB |
Output is correct |
38 |
Correct |
410 ms |
28996 KB |
Output is correct |
39 |
Correct |
398 ms |
29072 KB |
Output is correct |
40 |
Correct |
275 ms |
28860 KB |
Output is correct |
41 |
Correct |
277 ms |
28852 KB |
Output is correct |
42 |
Correct |
279 ms |
28848 KB |
Output is correct |
43 |
Correct |
214 ms |
28788 KB |
Output is correct |
44 |
Correct |
304 ms |
28852 KB |
Output is correct |
45 |
Correct |
408 ms |
28924 KB |
Output is correct |
46 |
Correct |
455 ms |
28988 KB |
Output is correct |
47 |
Correct |
253 ms |
28756 KB |
Output is correct |
48 |
Correct |
290 ms |
28972 KB |
Output is correct |
49 |
Correct |
383 ms |
28904 KB |
Output is correct |
50 |
Correct |
433 ms |
28976 KB |
Output is correct |
51 |
Correct |
239 ms |
28936 KB |
Output is correct |
52 |
Correct |
310 ms |
28860 KB |
Output is correct |
53 |
Correct |
375 ms |
28900 KB |
Output is correct |
54 |
Correct |
455 ms |
28972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
178 ms |
56164 KB |
Output is correct |
4 |
Correct |
262 ms |
74636 KB |
Output is correct |
5 |
Correct |
276 ms |
68964 KB |
Output is correct |
6 |
Correct |
203 ms |
58436 KB |
Output is correct |
7 |
Correct |
218 ms |
57504 KB |
Output is correct |
8 |
Correct |
176 ms |
51808 KB |
Output is correct |
9 |
Correct |
231 ms |
56732 KB |
Output is correct |
10 |
Correct |
308 ms |
70132 KB |
Output is correct |
11 |
Correct |
205 ms |
57200 KB |
Output is correct |
12 |
Correct |
249 ms |
68316 KB |
Output is correct |
13 |
Correct |
132 ms |
47948 KB |
Output is correct |
14 |
Correct |
211 ms |
52472 KB |
Output is correct |
15 |
Correct |
257 ms |
62720 KB |
Output is correct |
16 |
Correct |
298 ms |
70576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
16 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28420 KB |
Output is correct |
5 |
Correct |
14 ms |
28512 KB |
Output is correct |
6 |
Correct |
14 ms |
28460 KB |
Output is correct |
7 |
Correct |
16 ms |
28488 KB |
Output is correct |
8 |
Correct |
19 ms |
28552 KB |
Output is correct |
9 |
Correct |
18 ms |
28500 KB |
Output is correct |
10 |
Correct |
21 ms |
28500 KB |
Output is correct |
11 |
Correct |
20 ms |
28596 KB |
Output is correct |
12 |
Correct |
19 ms |
28512 KB |
Output is correct |
13 |
Correct |
18 ms |
28512 KB |
Output is correct |
14 |
Correct |
18 ms |
28540 KB |
Output is correct |
15 |
Correct |
18 ms |
28500 KB |
Output is correct |
16 |
Correct |
18 ms |
28536 KB |
Output is correct |
17 |
Correct |
17 ms |
28500 KB |
Output is correct |
18 |
Correct |
18 ms |
28592 KB |
Output is correct |
19 |
Correct |
18 ms |
28492 KB |
Output is correct |
20 |
Correct |
16 ms |
28576 KB |
Output is correct |
21 |
Correct |
17 ms |
28520 KB |
Output is correct |
22 |
Correct |
20 ms |
28592 KB |
Output is correct |
23 |
Correct |
20 ms |
28572 KB |
Output is correct |
24 |
Correct |
19 ms |
28632 KB |
Output is correct |
25 |
Correct |
21 ms |
28568 KB |
Output is correct |
26 |
Correct |
17 ms |
28520 KB |
Output is correct |
27 |
Correct |
19 ms |
28516 KB |
Output is correct |
28 |
Correct |
19 ms |
28596 KB |
Output is correct |
29 |
Correct |
178 ms |
56164 KB |
Output is correct |
30 |
Correct |
262 ms |
74636 KB |
Output is correct |
31 |
Correct |
276 ms |
68964 KB |
Output is correct |
32 |
Correct |
203 ms |
58436 KB |
Output is correct |
33 |
Correct |
218 ms |
57504 KB |
Output is correct |
34 |
Correct |
176 ms |
51808 KB |
Output is correct |
35 |
Correct |
231 ms |
56732 KB |
Output is correct |
36 |
Correct |
308 ms |
70132 KB |
Output is correct |
37 |
Correct |
205 ms |
57200 KB |
Output is correct |
38 |
Correct |
249 ms |
68316 KB |
Output is correct |
39 |
Correct |
132 ms |
47948 KB |
Output is correct |
40 |
Correct |
211 ms |
52472 KB |
Output is correct |
41 |
Correct |
257 ms |
62720 KB |
Output is correct |
42 |
Correct |
298 ms |
70576 KB |
Output is correct |
43 |
Execution timed out |
2061 ms |
62084 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
16 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28420 KB |
Output is correct |
5 |
Correct |
14 ms |
28512 KB |
Output is correct |
6 |
Correct |
14 ms |
28460 KB |
Output is correct |
7 |
Correct |
16 ms |
28488 KB |
Output is correct |
8 |
Correct |
19 ms |
28552 KB |
Output is correct |
9 |
Correct |
18 ms |
28500 KB |
Output is correct |
10 |
Correct |
21 ms |
28500 KB |
Output is correct |
11 |
Correct |
20 ms |
28596 KB |
Output is correct |
12 |
Correct |
19 ms |
28512 KB |
Output is correct |
13 |
Correct |
18 ms |
28512 KB |
Output is correct |
14 |
Correct |
18 ms |
28540 KB |
Output is correct |
15 |
Correct |
18 ms |
28500 KB |
Output is correct |
16 |
Correct |
18 ms |
28536 KB |
Output is correct |
17 |
Correct |
17 ms |
28500 KB |
Output is correct |
18 |
Correct |
18 ms |
28592 KB |
Output is correct |
19 |
Correct |
18 ms |
28492 KB |
Output is correct |
20 |
Correct |
16 ms |
28576 KB |
Output is correct |
21 |
Correct |
17 ms |
28520 KB |
Output is correct |
22 |
Correct |
20 ms |
28592 KB |
Output is correct |
23 |
Correct |
20 ms |
28572 KB |
Output is correct |
24 |
Correct |
19 ms |
28632 KB |
Output is correct |
25 |
Correct |
21 ms |
28568 KB |
Output is correct |
26 |
Correct |
17 ms |
28520 KB |
Output is correct |
27 |
Correct |
19 ms |
28516 KB |
Output is correct |
28 |
Correct |
19 ms |
28596 KB |
Output is correct |
29 |
Correct |
225 ms |
28888 KB |
Output is correct |
30 |
Correct |
422 ms |
28964 KB |
Output is correct |
31 |
Correct |
405 ms |
28936 KB |
Output is correct |
32 |
Correct |
302 ms |
28836 KB |
Output is correct |
33 |
Correct |
216 ms |
28792 KB |
Output is correct |
34 |
Correct |
456 ms |
28976 KB |
Output is correct |
35 |
Correct |
443 ms |
29096 KB |
Output is correct |
36 |
Correct |
232 ms |
28876 KB |
Output is correct |
37 |
Correct |
401 ms |
29016 KB |
Output is correct |
38 |
Correct |
410 ms |
28996 KB |
Output is correct |
39 |
Correct |
398 ms |
29072 KB |
Output is correct |
40 |
Correct |
275 ms |
28860 KB |
Output is correct |
41 |
Correct |
277 ms |
28852 KB |
Output is correct |
42 |
Correct |
279 ms |
28848 KB |
Output is correct |
43 |
Correct |
214 ms |
28788 KB |
Output is correct |
44 |
Correct |
304 ms |
28852 KB |
Output is correct |
45 |
Correct |
408 ms |
28924 KB |
Output is correct |
46 |
Correct |
455 ms |
28988 KB |
Output is correct |
47 |
Correct |
253 ms |
28756 KB |
Output is correct |
48 |
Correct |
290 ms |
28972 KB |
Output is correct |
49 |
Correct |
383 ms |
28904 KB |
Output is correct |
50 |
Correct |
433 ms |
28976 KB |
Output is correct |
51 |
Correct |
239 ms |
28936 KB |
Output is correct |
52 |
Correct |
310 ms |
28860 KB |
Output is correct |
53 |
Correct |
375 ms |
28900 KB |
Output is correct |
54 |
Correct |
455 ms |
28972 KB |
Output is correct |
55 |
Execution timed out |
2070 ms |
52816 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28492 KB |
Output is correct |
3 |
Correct |
16 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28420 KB |
Output is correct |
5 |
Correct |
14 ms |
28512 KB |
Output is correct |
6 |
Correct |
14 ms |
28460 KB |
Output is correct |
7 |
Correct |
16 ms |
28488 KB |
Output is correct |
8 |
Correct |
19 ms |
28552 KB |
Output is correct |
9 |
Correct |
18 ms |
28500 KB |
Output is correct |
10 |
Correct |
21 ms |
28500 KB |
Output is correct |
11 |
Correct |
20 ms |
28596 KB |
Output is correct |
12 |
Correct |
19 ms |
28512 KB |
Output is correct |
13 |
Correct |
18 ms |
28512 KB |
Output is correct |
14 |
Correct |
18 ms |
28540 KB |
Output is correct |
15 |
Correct |
18 ms |
28500 KB |
Output is correct |
16 |
Correct |
18 ms |
28536 KB |
Output is correct |
17 |
Correct |
17 ms |
28500 KB |
Output is correct |
18 |
Correct |
18 ms |
28592 KB |
Output is correct |
19 |
Correct |
18 ms |
28492 KB |
Output is correct |
20 |
Correct |
16 ms |
28576 KB |
Output is correct |
21 |
Correct |
17 ms |
28520 KB |
Output is correct |
22 |
Correct |
20 ms |
28592 KB |
Output is correct |
23 |
Correct |
20 ms |
28572 KB |
Output is correct |
24 |
Correct |
19 ms |
28632 KB |
Output is correct |
25 |
Correct |
21 ms |
28568 KB |
Output is correct |
26 |
Correct |
17 ms |
28520 KB |
Output is correct |
27 |
Correct |
19 ms |
28516 KB |
Output is correct |
28 |
Correct |
19 ms |
28596 KB |
Output is correct |
29 |
Correct |
225 ms |
28888 KB |
Output is correct |
30 |
Correct |
422 ms |
28964 KB |
Output is correct |
31 |
Correct |
405 ms |
28936 KB |
Output is correct |
32 |
Correct |
302 ms |
28836 KB |
Output is correct |
33 |
Correct |
216 ms |
28792 KB |
Output is correct |
34 |
Correct |
456 ms |
28976 KB |
Output is correct |
35 |
Correct |
443 ms |
29096 KB |
Output is correct |
36 |
Correct |
232 ms |
28876 KB |
Output is correct |
37 |
Correct |
401 ms |
29016 KB |
Output is correct |
38 |
Correct |
410 ms |
28996 KB |
Output is correct |
39 |
Correct |
398 ms |
29072 KB |
Output is correct |
40 |
Correct |
275 ms |
28860 KB |
Output is correct |
41 |
Correct |
277 ms |
28852 KB |
Output is correct |
42 |
Correct |
279 ms |
28848 KB |
Output is correct |
43 |
Correct |
214 ms |
28788 KB |
Output is correct |
44 |
Correct |
304 ms |
28852 KB |
Output is correct |
45 |
Correct |
408 ms |
28924 KB |
Output is correct |
46 |
Correct |
455 ms |
28988 KB |
Output is correct |
47 |
Correct |
253 ms |
28756 KB |
Output is correct |
48 |
Correct |
290 ms |
28972 KB |
Output is correct |
49 |
Correct |
383 ms |
28904 KB |
Output is correct |
50 |
Correct |
433 ms |
28976 KB |
Output is correct |
51 |
Correct |
239 ms |
28936 KB |
Output is correct |
52 |
Correct |
310 ms |
28860 KB |
Output is correct |
53 |
Correct |
375 ms |
28900 KB |
Output is correct |
54 |
Correct |
455 ms |
28972 KB |
Output is correct |
55 |
Correct |
178 ms |
56164 KB |
Output is correct |
56 |
Correct |
262 ms |
74636 KB |
Output is correct |
57 |
Correct |
276 ms |
68964 KB |
Output is correct |
58 |
Correct |
203 ms |
58436 KB |
Output is correct |
59 |
Correct |
218 ms |
57504 KB |
Output is correct |
60 |
Correct |
176 ms |
51808 KB |
Output is correct |
61 |
Correct |
231 ms |
56732 KB |
Output is correct |
62 |
Correct |
308 ms |
70132 KB |
Output is correct |
63 |
Correct |
205 ms |
57200 KB |
Output is correct |
64 |
Correct |
249 ms |
68316 KB |
Output is correct |
65 |
Correct |
132 ms |
47948 KB |
Output is correct |
66 |
Correct |
211 ms |
52472 KB |
Output is correct |
67 |
Correct |
257 ms |
62720 KB |
Output is correct |
68 |
Correct |
298 ms |
70576 KB |
Output is correct |
69 |
Execution timed out |
2061 ms |
62084 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |