Submission #925915

# Submission time Handle Problem Language Result Execution time Memory
925915 2024-02-12T10:43:13 Z vjudge1 Joker (BOI20_joker) C++17
0 / 100
582 ms 53300 KB
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>

using namespace std;

const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7; 

int mult(int x, int y) {
	return 1ll*x*y%MOD;
}

int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}

int sub(int x, int y) {
	x -= y;
	if(x < 0) {
		x += MOD;
	}
	return x;
}

int n, m, q;
pair<int, int> e[N];
vector<int> g[N];
int used[N];

bool dfs(int v) {
	for(auto to : g[v]) {
		if(!used[to]) {
			used[to] = 3-used[v];
			if(dfs(to)) {
				return 1;
			}
		} else if(used[to] == used[v]) {
			return 1;
		}
	}
	return 0;
}

bool solve(int l, int r) {
	for(int i = 1; i <= n; ++i) {
		g[i].clear();
		used[i] = 0;
	}
	for(int i = 1; i <= m; ++i) {
		if(i >= l && i <= r) {
			continue;
		}
		int u = e[i].first;
		int v = e[i].second;
		g[u].push_back(v);
		g[v].push_back(u);
	}             
	for(int i = 1; i <= n; ++i) {
		if(!used[i]) {
			used[i] = 1;
			if(dfs(i)) {
				return 1;
			}			
		}
	}
	return 0;
}

bool ans[201][N];
int p[N], len[N], sz[N];

pair<int, int> get(int v) {
	if(v == p[v]) {
		return {v, 0};
	}
	pair<int, int> cur = get(p[v]);
	p[v] = cur.first;
	len[v] += cur.second;
	return {p[v], len[v]};
}

bool comb(int u, int v) {
	pair<int, int> p1 = get(u);
	pair<int, int> p2 = get(v);
	if(sz[p1.first] > sz[p2.first]) {
		swap(p1, p2);
	}
	if(p1.first != p2.first) {
		p[p2.first]=p1.first;
		sz[p2.first] += sz[p1.first];
		len[p2.first]=1;
		return 1;
	}
	if(p1.second%2 == p2.second%2) {
		return 0;
	}
	return 1;
}

void init() {
	for(int l = 1; l <= min(200, m); ++l) {
		for(int i = 1; i <= n; ++i) {
			p[i] = i;
			len[i] = 0;
			sz[i] = i;
		}
		bool is = 0;
		for(int i = 1; i < l; ++i) {
			int u = e[i].first;
			int v = e[i].second;
			if(!comb(u, v)) {
				is = 1;
				break;
			}			
		}
		if(is) {
			for(int r = l; r <= m; ++r) {
				ans[l][r] = 1;
			}
			continue;
		}
		for(int r = m; r >= l; --r) {
			int u = e[r].first;
			int v = e[r].second;
			ans[l][r] = ans[l][r+1];
			if(ans[l][r]) {
				continue;
			}
			if(!comb(u, v)) {
			//	cout << "yes\n";
			//	cout << "x : " << l << ' ' << r << "\n";
				ans[l][r] = 1;	
			}
		}	
	}
}

int main() {	
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cin >> n >> m >> q;
	for(int i = 1; i <= m; ++i) {
		cin >> e[i].first >> e[i].second;
	}       
	init();
	for(int i = 1; i <= q; ++i) {
		int l, r;
		cin >> l >> r;
		if(l <= 200) {
			cout << (ans[l][r+1] ? "YES\n" : "NO\n");
			continue;
		}
		cout << (solve(l, r) ? "YES\n" : "NO\n");
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Incorrect 2 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Incorrect 2 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 533 ms 51704 KB Output is correct
4 Incorrect 582 ms 53300 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Incorrect 2 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Incorrect 2 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Incorrect 2 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -