답안 #1033906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033906 2024-07-25T07:41:38 Z goodspeed0208 Joker (BOI20_joker) C++14
0 / 100
2000 ms 4084 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];
	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] = fa;
	}
	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";
	}
}








# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2027 ms 4084 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -