Submission #642330

# Submission time Handle Problem Language Result Execution time Memory
642330 2022-09-19T08:49:29 Z dozer Joker (BOI20_joker) C++14
0 / 100
1105 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 400005

const int modulo = 1e9 + 7;
int ans[N], u[N], v[N], l[N], r[N], n;
vector<int> ind[N], root, gh[N];
map<int, int> res[N];

int find(vector<int> &b, int node)
{
	if (node < 0) return -(find(b, -node));
	if (node == b[node]) return node;
	if (node == -b[node]) return 0;
	return b[node] = find(b, b[node]);
}


int32_t main()
{
	fastio();


	int m, q;
	cin>>n>>m>>q;
	root.resize(n + 5, 0);
	for (int i = 1; i <= n; i++)
		root[i] = i;

	for (int i = 1; i <= m; i++)
	{
		cin>>u[i]>>v[i];
	}

	for (int i = 1; i <= q; i++)
	{
		cin>>l[i]>>r[i];
		ind[l[i]].pb(r[i]);
	}


	for (int t = 1; t <= min(200, m); t++)
	{
		for (int i = 1; i <= n; i++) root[i] = i;
		for (int i = 1; i < t; i++)
		{
			if (ans[i] == 1) 
			{
				ans[i + 1] = 1;
				continue;
			}
			int a = find(root, u[i]), b = find(root, v[i]);
			if (a == b) 
			{
				ans[i + 1] = 1;
			}
			else
			{
				if (a < 0) a *= -1, b *= -1;
				root[a] = -b;
			}		
		}
		for (int i = m; i >= 1; i--)
		{
			if (res[t][i] == 1 || ans[t] == 1) 
			{
				res[t][i - 1] = 1;
				continue;
			}
			int a = find(root, u[i]), b = find(root, v[i]);
			if (a == b) 
			{
				res[t][i - 1] = 1;
			}
			else
			{
				if (a < 0) a *= -1, b *= -1;
				root[a] = -b;
			}
			//cout<<i<<sp<<ans[i]<<endl;
		}
	}

	for (int i = 1; i <= q; i++)
	{
		if (res[l[i]][r[i]]) cout<<"YES\n";
		else cout<<"NO\n";
	}
		
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 19 ms 37888 KB Output is correct
4 Incorrect 17 ms 37868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 19 ms 37888 KB Output is correct
4 Incorrect 17 ms 37868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Runtime error 1105 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 19 ms 37888 KB Output is correct
4 Incorrect 17 ms 37868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 19 ms 37888 KB Output is correct
4 Incorrect 17 ms 37868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37816 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 19 ms 37888 KB Output is correct
4 Incorrect 17 ms 37868 KB Output isn't correct
5 Halted 0 ms 0 KB -