Submission #417234

#TimeUsernameProblemLanguageResultExecution timeMemory
417234aryan12Joker (BOI20_joker)C++17
39 / 100
565 ms23456 KiB
#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 (stderr)

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++) {
      |                 ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...