Submission #999809

# Submission time Handle Problem Language Result Execution time Memory
999809 2024-06-16T07:13:30 Z Mr_Husanboy Joker (BOI20_joker) C++17
39 / 100
2000 ms 28016 KB
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
 
template<typename T>
int len(T &a){return a.size();}
 
 
struct DSU{
	vector<vector<int>> child;
	vector<int> l;
	vector<int> col;
	int n;
	bool odd = 0;
 
	DSU (int _n){init(_n);}
 
	void init(int _n){
		n = _n;
		child.resize(n);
		l.resize(n); iota(all(l), 0);
		col.assign(n, 0);
		for(int i = 0; i < n; i ++){
			child[i] = {i};
		}
	}
 
	void unite(int a, int b){
		if(l[a] == l[b]){
			if(col[a] == col[b]) odd = 1;
			return;
		}
		if(len(child[l[a]]) > len(child[l[b]])) swap(a, b);
		if(col[a] == col[b]){
			for(auto u : child[l[a]]) col[u] ^= 1;
		}
		a = l[a], b = l[b];
		for(auto u : child[a]){
			child[b].push_back(u);
			l[u] = b;
		}
		child[a].clear();
	}
};
 
void solve(){
	int n, m, q; cin >> n >> m >> q;
	vector<pair<int,int>> edge(m);
	for(auto &[a, b] : edge) cin >> a >> b, a --, b --;
 
	vector<vector<pair<int,int>>> qu(m);
 
	for(int i = 0; i < q; i ++){
		int l, r; 
		cin >> l >> r;
		l --; r --;
		qu[l].push_back({r, i});
	}
	vector<int> ans(q);
	for(int i = 0; i < m; i ++){
		if(len(qu[i]) == 0) continue;
 
		DSU t(n);
		//cout << i << endl;
		for(int j = 0; j < i; j ++){
			//cout << edge[j].ff << endl;
			t.unite(edge[j].ff, edge[j].ss);
		}
		int r = m;
		if(t.odd == 0){
			r = i - 1;
			for(int j = m - 1; j >= i; j --){
				t.unite(edge[j].ff, edge[j].ss);
				if(t.odd){
					r = j;
					break;
				}
			}
		}
		for(auto [rig, j] : qu[i]){
			ans[j] = rig < r;
		}
	}
	for(auto u : ans){
		cout << (u ? "YES" : "NO") << '\n';
	}
}
 
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int tests = 1;
	while(tests --){
		solve();
	}
	#ifdef LOCAL
	cout << "\nDone" << endl;
	#endif
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 2 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 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 2 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 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 83 ms 664 KB Output is correct
30 Correct 128 ms 728 KB Output is correct
31 Correct 111 ms 604 KB Output is correct
32 Correct 71 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 132 ms 748 KB Output is correct
35 Correct 133 ms 740 KB Output is correct
36 Correct 69 ms 604 KB Output is correct
37 Correct 129 ms 600 KB Output is correct
38 Correct 149 ms 740 KB Output is correct
39 Correct 96 ms 508 KB Output is correct
40 Correct 85 ms 660 KB Output is correct
41 Correct 68 ms 604 KB Output is correct
42 Correct 65 ms 604 KB Output is correct
43 Correct 46 ms 604 KB Output is correct
44 Correct 70 ms 604 KB Output is correct
45 Correct 108 ms 604 KB Output is correct
46 Correct 134 ms 600 KB Output is correct
47 Correct 58 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 94 ms 604 KB Output is correct
50 Correct 131 ms 724 KB Output is correct
51 Correct 53 ms 604 KB Output is correct
52 Correct 71 ms 604 KB Output is correct
53 Correct 95 ms 604 KB Output is correct
54 Correct 133 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 58 ms 18636 KB Output is correct
4 Correct 75 ms 25420 KB Output is correct
5 Correct 62 ms 22480 KB Output is correct
6 Correct 61 ms 20172 KB Output is correct
7 Correct 60 ms 20968 KB Output is correct
8 Correct 60 ms 16584 KB Output is correct
9 Correct 62 ms 19800 KB Output is correct
10 Correct 70 ms 25684 KB Output is correct
11 Correct 61 ms 19916 KB Output is correct
12 Correct 71 ms 25040 KB Output is correct
13 Correct 50 ms 15052 KB Output is correct
14 Correct 71 ms 17356 KB Output is correct
15 Correct 85 ms 22988 KB Output is correct
16 Correct 75 ms 26400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 2 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 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 58 ms 18636 KB Output is correct
30 Correct 75 ms 25420 KB Output is correct
31 Correct 62 ms 22480 KB Output is correct
32 Correct 61 ms 20172 KB Output is correct
33 Correct 60 ms 20968 KB Output is correct
34 Correct 60 ms 16584 KB Output is correct
35 Correct 62 ms 19800 KB Output is correct
36 Correct 70 ms 25684 KB Output is correct
37 Correct 61 ms 19916 KB Output is correct
38 Correct 71 ms 25040 KB Output is correct
39 Correct 50 ms 15052 KB Output is correct
40 Correct 71 ms 17356 KB Output is correct
41 Correct 85 ms 22988 KB Output is correct
42 Correct 75 ms 26400 KB Output is correct
43 Correct 1746 ms 21680 KB Output is correct
44 Execution timed out 2083 ms 28016 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 2 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 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 83 ms 664 KB Output is correct
30 Correct 128 ms 728 KB Output is correct
31 Correct 111 ms 604 KB Output is correct
32 Correct 71 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 132 ms 748 KB Output is correct
35 Correct 133 ms 740 KB Output is correct
36 Correct 69 ms 604 KB Output is correct
37 Correct 129 ms 600 KB Output is correct
38 Correct 149 ms 740 KB Output is correct
39 Correct 96 ms 508 KB Output is correct
40 Correct 85 ms 660 KB Output is correct
41 Correct 68 ms 604 KB Output is correct
42 Correct 65 ms 604 KB Output is correct
43 Correct 46 ms 604 KB Output is correct
44 Correct 70 ms 604 KB Output is correct
45 Correct 108 ms 604 KB Output is correct
46 Correct 134 ms 600 KB Output is correct
47 Correct 58 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 94 ms 604 KB Output is correct
50 Correct 131 ms 724 KB Output is correct
51 Correct 53 ms 604 KB Output is correct
52 Correct 71 ms 604 KB Output is correct
53 Correct 95 ms 604 KB Output is correct
54 Correct 133 ms 604 KB Output is correct
55 Execution timed out 2013 ms 16628 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 2 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 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 83 ms 664 KB Output is correct
30 Correct 128 ms 728 KB Output is correct
31 Correct 111 ms 604 KB Output is correct
32 Correct 71 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 132 ms 748 KB Output is correct
35 Correct 133 ms 740 KB Output is correct
36 Correct 69 ms 604 KB Output is correct
37 Correct 129 ms 600 KB Output is correct
38 Correct 149 ms 740 KB Output is correct
39 Correct 96 ms 508 KB Output is correct
40 Correct 85 ms 660 KB Output is correct
41 Correct 68 ms 604 KB Output is correct
42 Correct 65 ms 604 KB Output is correct
43 Correct 46 ms 604 KB Output is correct
44 Correct 70 ms 604 KB Output is correct
45 Correct 108 ms 604 KB Output is correct
46 Correct 134 ms 600 KB Output is correct
47 Correct 58 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 94 ms 604 KB Output is correct
50 Correct 131 ms 724 KB Output is correct
51 Correct 53 ms 604 KB Output is correct
52 Correct 71 ms 604 KB Output is correct
53 Correct 95 ms 604 KB Output is correct
54 Correct 133 ms 604 KB Output is correct
55 Correct 58 ms 18636 KB Output is correct
56 Correct 75 ms 25420 KB Output is correct
57 Correct 62 ms 22480 KB Output is correct
58 Correct 61 ms 20172 KB Output is correct
59 Correct 60 ms 20968 KB Output is correct
60 Correct 60 ms 16584 KB Output is correct
61 Correct 62 ms 19800 KB Output is correct
62 Correct 70 ms 25684 KB Output is correct
63 Correct 61 ms 19916 KB Output is correct
64 Correct 71 ms 25040 KB Output is correct
65 Correct 50 ms 15052 KB Output is correct
66 Correct 71 ms 17356 KB Output is correct
67 Correct 85 ms 22988 KB Output is correct
68 Correct 75 ms 26400 KB Output is correct
69 Correct 1746 ms 21680 KB Output is correct
70 Execution timed out 2083 ms 28016 KB Time limit exceeded
71 Halted 0 ms 0 KB -