답안 #417234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417234 2021-06-03T13:42:48 Z aryan12 Joker (BOI20_joker) C++17
39 / 100
565 ms 23456 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
const int N = 200005;
vector<int> g[N];
int color[N];
 
bool dfs(int node, int col) {
	color[node] = col;
	for(int i = 0; i < g[node].size(); i++) {
		if(color[g[node][i]] == -1) {
			if(dfs(g[node][i], 1 - col))
				return true;
		}
		else if(color[g[node][i]] == color[node])
			return true;
	}
	return false;
}
 
bool isBipartite(int n) {
	for(int i = 1; i <= n; i++) {
		if(color[i] == -1) {
			if(dfs(i, 0))
				return true;
		}
	}
	return false;
}
 
void Solve() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<pair<int, int> > edges;
	for(int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		edges.push_back(make_pair(u, v));
	}
	if(n <= 2000 && m <= 2000 && q <= 2000) {
		for(int i = 1; i <= q; i++) {
			for(int i = 0; i <= n; i++) {
				color[i] = -1;
				g[i].clear();
			}
			int left, right;
			cin >> left >> right;
			left--, right--;
			for(int i = 0; i < left; i++) {
				g[edges[i].first].push_back(edges[i].second);
				g[edges[i].second].push_back(edges[i].first);
			}
			for(int i = right + 1; i < m; i++) {
				g[edges[i].first].push_back(edges[i].second);
				g[edges[i].second].push_back(edges[i].first);	
			}
			if(isBipartite(n)) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
		}
	}
	else {
		int left = 0, right = m - 1;
		int mid, ans = 0;
		while(left <= right) {
			mid = (left + right) >> 1;
			for(int i = 1; i <= n; i++) {
				g[i].clear();
				color[i] = -1;
			}
			for(int i = m - 1; i >= mid; i--) {
				g[edges[i].first].push_back(edges[i].second);
				g[edges[i].second].push_back(edges[i].first);
			}
			if(isBipartite(n)) {
				left = mid + 1;
				ans = mid;
			}
			else {
				right = mid - 1;
			}
		}
		for(int i = 1; i <= q; i++) {
			int l, r;
			cin >> l >> r;
			l--, r--;
			if(ans > r) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
		}
	}
}
 
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	return 0;
}

Compilation message

Joker.cpp: In function 'bool dfs(long long int, long long int)':
Joker.cpp:13:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i = 0; i < g[node].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5012 KB Output is correct
10 Correct 4 ms 5008 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 5016 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 5 ms 5020 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 5016 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5012 KB Output is correct
10 Correct 4 ms 5008 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 5016 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 5 ms 5020 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 5016 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 113 ms 5096 KB Output is correct
30 Correct 107 ms 5168 KB Output is correct
31 Correct 99 ms 5164 KB Output is correct
32 Correct 68 ms 5160 KB Output is correct
33 Correct 51 ms 5068 KB Output is correct
34 Correct 98 ms 5180 KB Output is correct
35 Correct 116 ms 5168 KB Output is correct
36 Correct 59 ms 5192 KB Output is correct
37 Correct 132 ms 5196 KB Output is correct
38 Correct 148 ms 5168 KB Output is correct
39 Correct 91 ms 5280 KB Output is correct
40 Correct 63 ms 5176 KB Output is correct
41 Correct 63 ms 5276 KB Output is correct
42 Correct 61 ms 5140 KB Output is correct
43 Correct 75 ms 5164 KB Output is correct
44 Correct 81 ms 5068 KB Output is correct
45 Correct 91 ms 5168 KB Output is correct
46 Correct 100 ms 5160 KB Output is correct
47 Correct 64 ms 5188 KB Output is correct
48 Correct 70 ms 5152 KB Output is correct
49 Correct 84 ms 5152 KB Output is correct
50 Correct 99 ms 5160 KB Output is correct
51 Correct 64 ms 5068 KB Output is correct
52 Correct 74 ms 5156 KB Output is correct
53 Correct 89 ms 5160 KB Output is correct
54 Correct 112 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 216 ms 20668 KB Output is correct
4 Correct 565 ms 23456 KB Output is correct
5 Correct 168 ms 18040 KB Output is correct
6 Correct 226 ms 17896 KB Output is correct
7 Correct 267 ms 17200 KB Output is correct
8 Correct 242 ms 17292 KB Output is correct
9 Correct 304 ms 17932 KB Output is correct
10 Correct 405 ms 19676 KB Output is correct
11 Correct 207 ms 18532 KB Output is correct
12 Correct 297 ms 19672 KB Output is correct
13 Correct 188 ms 16268 KB Output is correct
14 Correct 255 ms 17892 KB Output is correct
15 Correct 315 ms 19644 KB Output is correct
16 Correct 435 ms 20088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5012 KB Output is correct
10 Correct 4 ms 5008 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 5016 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 5 ms 5020 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 5016 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 216 ms 20668 KB Output is correct
30 Correct 565 ms 23456 KB Output is correct
31 Correct 168 ms 18040 KB Output is correct
32 Correct 226 ms 17896 KB Output is correct
33 Correct 267 ms 17200 KB Output is correct
34 Correct 242 ms 17292 KB Output is correct
35 Correct 304 ms 17932 KB Output is correct
36 Correct 405 ms 19676 KB Output is correct
37 Correct 207 ms 18532 KB Output is correct
38 Correct 297 ms 19672 KB Output is correct
39 Correct 188 ms 16268 KB Output is correct
40 Correct 255 ms 17892 KB Output is correct
41 Correct 315 ms 19644 KB Output is correct
42 Correct 435 ms 20088 KB Output is correct
43 Incorrect 250 ms 20400 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5012 KB Output is correct
10 Correct 4 ms 5008 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 5016 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 5 ms 5020 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 5016 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 113 ms 5096 KB Output is correct
30 Correct 107 ms 5168 KB Output is correct
31 Correct 99 ms 5164 KB Output is correct
32 Correct 68 ms 5160 KB Output is correct
33 Correct 51 ms 5068 KB Output is correct
34 Correct 98 ms 5180 KB Output is correct
35 Correct 116 ms 5168 KB Output is correct
36 Correct 59 ms 5192 KB Output is correct
37 Correct 132 ms 5196 KB Output is correct
38 Correct 148 ms 5168 KB Output is correct
39 Correct 91 ms 5280 KB Output is correct
40 Correct 63 ms 5176 KB Output is correct
41 Correct 63 ms 5276 KB Output is correct
42 Correct 61 ms 5140 KB Output is correct
43 Correct 75 ms 5164 KB Output is correct
44 Correct 81 ms 5068 KB Output is correct
45 Correct 91 ms 5168 KB Output is correct
46 Correct 100 ms 5160 KB Output is correct
47 Correct 64 ms 5188 KB Output is correct
48 Correct 70 ms 5152 KB Output is correct
49 Correct 84 ms 5152 KB Output is correct
50 Correct 99 ms 5160 KB Output is correct
51 Correct 64 ms 5068 KB Output is correct
52 Correct 74 ms 5156 KB Output is correct
53 Correct 89 ms 5160 KB Output is correct
54 Correct 112 ms 5068 KB Output is correct
55 Incorrect 204 ms 19736 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5012 KB Output is correct
10 Correct 4 ms 5008 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 5016 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 5 ms 5020 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 5016 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 113 ms 5096 KB Output is correct
30 Correct 107 ms 5168 KB Output is correct
31 Correct 99 ms 5164 KB Output is correct
32 Correct 68 ms 5160 KB Output is correct
33 Correct 51 ms 5068 KB Output is correct
34 Correct 98 ms 5180 KB Output is correct
35 Correct 116 ms 5168 KB Output is correct
36 Correct 59 ms 5192 KB Output is correct
37 Correct 132 ms 5196 KB Output is correct
38 Correct 148 ms 5168 KB Output is correct
39 Correct 91 ms 5280 KB Output is correct
40 Correct 63 ms 5176 KB Output is correct
41 Correct 63 ms 5276 KB Output is correct
42 Correct 61 ms 5140 KB Output is correct
43 Correct 75 ms 5164 KB Output is correct
44 Correct 81 ms 5068 KB Output is correct
45 Correct 91 ms 5168 KB Output is correct
46 Correct 100 ms 5160 KB Output is correct
47 Correct 64 ms 5188 KB Output is correct
48 Correct 70 ms 5152 KB Output is correct
49 Correct 84 ms 5152 KB Output is correct
50 Correct 99 ms 5160 KB Output is correct
51 Correct 64 ms 5068 KB Output is correct
52 Correct 74 ms 5156 KB Output is correct
53 Correct 89 ms 5160 KB Output is correct
54 Correct 112 ms 5068 KB Output is correct
55 Correct 216 ms 20668 KB Output is correct
56 Correct 565 ms 23456 KB Output is correct
57 Correct 168 ms 18040 KB Output is correct
58 Correct 226 ms 17896 KB Output is correct
59 Correct 267 ms 17200 KB Output is correct
60 Correct 242 ms 17292 KB Output is correct
61 Correct 304 ms 17932 KB Output is correct
62 Correct 405 ms 19676 KB Output is correct
63 Correct 207 ms 18532 KB Output is correct
64 Correct 297 ms 19672 KB Output is correct
65 Correct 188 ms 16268 KB Output is correct
66 Correct 255 ms 17892 KB Output is correct
67 Correct 315 ms 19644 KB Output is correct
68 Correct 435 ms 20088 KB Output is correct
69 Incorrect 250 ms 20400 KB Output isn't correct
70 Halted 0 ms 0 KB -