Submission #1033943

# Submission time Handle Problem Language Result Execution time Memory
1033943 2024-07-25T08:00:29 Z goodspeed0208 Joker (BOI20_joker) C++14
14 / 100
2000 ms 6700 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;

int n, m, q;
vector<int>f, sz, same, dif;

void init() {
	for (int i = 0 ; i < n ; i++) {
		f[i] = i;
		same[i] = i;
		dif[i] = -1;
		sz[i] = 1;
	}
}

int find(int x) {
	//if (f[x][j] == -1) return -1;
	if (x == f[x]) return x;
	else return f[x] = find(f[x]);
}

int finds(int x) {
	if (x == -1) return -1;
	if (x == same[x]) return x;
	else return same[x] = finds(same[x]);
}

bool add(int a, int b) {
	int fa = find(a), fb = find(b);
	int sa = finds(a), sb = finds(b);
	//cout << fa << " " << sa << " " << fb << " " << sb << "\n";
	if (fa == fb) {
		if (sa == sb) return true;
		else return false;
	}
	/*if (sz[fa] > sz[fb]) {
		swap(fa, fb); swap(sa, sb);
	}*/
	f[fa] = fb;
	sz[fb] += sz[fa];
	//cout << fa << " " << dif[fa] << " " << finds(dif[fa]) << "\n";
	assert(dif[fa] == finds(dif[fa]));
	assert(dif[fb] == finds(dif[fb]));
	dif[fa] = finds(dif[fa]); dif[fb] = finds(dif[fb]);
	if ((fa == sa && fb == sb) || (fa != sa && fb != sb)) {
		if (dif[fa] != -1) same[dif[fa]] = fb;
		if (dif[fb] != -1) same[fa] = dif[fb];
		else dif[fb] = fa;
	} else {
		same[fa] = fb;
		if (dif[fa] != -1 && dif[fb] != -1) same[dif[fa]] = dif[fb];
		else if (dif[fa] != -1) dif[fb] = dif[fa];
	}
	//for (int i = 0 ; i < n ; i++) cout << find(i) << " "; cout << "\n";
	//for (int i = 0 ; i < n ; i++) cout << finds(i) << " "; cout <<"\n";
	//cout << "\n";
	return false;
}

signed main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	cin >> n >> m >> q;
	f.resize(n);
	sz.resize(n);
	same.resize(n);
	dif.resize(n);
	vector<pii>e;
	int a, b;
	for (int i = 0 ; i < m ; i++) {
		cin >> a >> b; a--, b--;
		e.push_back({a, b});
	}
	int l, r;
	for (int i = 0 ; i < q ; i++) {
		init();
		bool can = 0;
		cin >> l>> r; l--, r--;
		for (int j = 0 ; j < l && !can ; j++) {
			//cout << e[j].first << " " << e[j].second << "\n";
			can = add(e[j].first, e[j].second);
			//cout << j << " ";
		}
		for (int j = r+1 ; j < m && !can ; j++) {
			can = add(e[j].first, e[j].second);
			//cout << j << " ";
		}
		if (can) cout <<"YES\n";
		else cout << "NO\n";
	}
}








# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 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 348 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 436 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 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 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 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 348 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 436 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 1 ms 348 KB Output is correct
29 Correct 29 ms 348 KB Output is correct
30 Correct 35 ms 344 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 19 ms 348 KB Output is correct
33 Correct 12 ms 348 KB Output is correct
34 Correct 25 ms 348 KB Output is correct
35 Correct 46 ms 532 KB Output is correct
36 Correct 27 ms 344 KB Output is correct
37 Correct 45 ms 348 KB Output is correct
38 Correct 56 ms 536 KB Output is correct
39 Correct 40 ms 344 KB Output is correct
40 Correct 24 ms 348 KB Output is correct
41 Correct 24 ms 348 KB Output is correct
42 Correct 25 ms 520 KB Output is correct
43 Correct 32 ms 348 KB Output is correct
44 Correct 35 ms 520 KB Output is correct
45 Correct 33 ms 348 KB Output is correct
46 Correct 32 ms 344 KB Output is correct
47 Correct 26 ms 344 KB Output is correct
48 Correct 26 ms 344 KB Output is correct
49 Correct 30 ms 532 KB Output is correct
50 Correct 33 ms 348 KB Output is correct
51 Correct 30 ms 512 KB Output is correct
52 Correct 31 ms 348 KB Output is correct
53 Correct 32 ms 344 KB Output is correct
54 Correct 39 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 Execution timed out 2070 ms 6700 KB Time limit exceeded
4 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 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 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 348 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 436 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 1 ms 348 KB Output is correct
29 Execution timed out 2070 ms 6700 KB Time limit exceeded
30 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 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 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 348 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 436 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 1 ms 348 KB Output is correct
29 Correct 29 ms 348 KB Output is correct
30 Correct 35 ms 344 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 19 ms 348 KB Output is correct
33 Correct 12 ms 348 KB Output is correct
34 Correct 25 ms 348 KB Output is correct
35 Correct 46 ms 532 KB Output is correct
36 Correct 27 ms 344 KB Output is correct
37 Correct 45 ms 348 KB Output is correct
38 Correct 56 ms 536 KB Output is correct
39 Correct 40 ms 344 KB Output is correct
40 Correct 24 ms 348 KB Output is correct
41 Correct 24 ms 348 KB Output is correct
42 Correct 25 ms 520 KB Output is correct
43 Correct 32 ms 348 KB Output is correct
44 Correct 35 ms 520 KB Output is correct
45 Correct 33 ms 348 KB Output is correct
46 Correct 32 ms 344 KB Output is correct
47 Correct 26 ms 344 KB Output is correct
48 Correct 26 ms 344 KB Output is correct
49 Correct 30 ms 532 KB Output is correct
50 Correct 33 ms 348 KB Output is correct
51 Correct 30 ms 512 KB Output is correct
52 Correct 31 ms 348 KB Output is correct
53 Correct 32 ms 344 KB Output is correct
54 Correct 39 ms 348 KB Output is correct
55 Execution timed out 2059 ms 6312 KB Time limit exceeded
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 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 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 348 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 436 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 1 ms 348 KB Output is correct
29 Correct 29 ms 348 KB Output is correct
30 Correct 35 ms 344 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 19 ms 348 KB Output is correct
33 Correct 12 ms 348 KB Output is correct
34 Correct 25 ms 348 KB Output is correct
35 Correct 46 ms 532 KB Output is correct
36 Correct 27 ms 344 KB Output is correct
37 Correct 45 ms 348 KB Output is correct
38 Correct 56 ms 536 KB Output is correct
39 Correct 40 ms 344 KB Output is correct
40 Correct 24 ms 348 KB Output is correct
41 Correct 24 ms 348 KB Output is correct
42 Correct 25 ms 520 KB Output is correct
43 Correct 32 ms 348 KB Output is correct
44 Correct 35 ms 520 KB Output is correct
45 Correct 33 ms 348 KB Output is correct
46 Correct 32 ms 344 KB Output is correct
47 Correct 26 ms 344 KB Output is correct
48 Correct 26 ms 344 KB Output is correct
49 Correct 30 ms 532 KB Output is correct
50 Correct 33 ms 348 KB Output is correct
51 Correct 30 ms 512 KB Output is correct
52 Correct 31 ms 348 KB Output is correct
53 Correct 32 ms 344 KB Output is correct
54 Correct 39 ms 348 KB Output is correct
55 Execution timed out 2070 ms 6700 KB Time limit exceeded
56 Halted 0 ms 0 KB -