답안 #858784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858784 2023-10-09T07:43:23 Z maks007 Joker (BOI20_joker) C++14
14 / 100
2000 ms 8052 KB
#include "bits/stdc++.h"

using namespace std;

vector <vector <int> > g;
vector <int> used, rk, p;
int f;

int get(int v) {
	if(v == p[v]) return v;
	return p[v] = get(p[v]);
}

void unite(int a, int b) {
	a = get(a);
	b = get(b);
	if(a == b) return;
	rk[a] += rk[b];
	p[b] = a;
}

void dfs(int v, int dist = 1, int p = -1) {
	used[v] = dist;
	for(auto i : g[v]) {
		if(p == i) continue;
		if(used[i]==-1) dfs(i, (dist+1)%2, v);
		else {
			if(used[i] == used[v]) f = 1;
		}
	}
}
void renname(int v, int p) {
	used[v] = 1-used[v];
	for(auto i : g[v]) {
		if(i == p) continue;
		renname(i, v);
	}
}
void d(int v, int u) {
	if(used[v] + used[u] == -2) {
		used[v] = 1;
		used[u] = 0;
	//}else if(used[v] == -1 || used[u] == -1) {
	// 	int nul = 0, one = 0;
	// 	if(used[u] == -1) swap(u, v);
	// 	for(auto i : g[v]) {
	// 		if(used[i] == 1) one ++;
	// 		else nul ++;
	// 	}
	// 	if(one == 0) used[v] = 1;
	// 	else if(nul == 0) used[v] = 0;
	// 	else {
	// 		used[v] = 1;
	// 		f = 1;
	// 	} 
	 }else {
		for(auto &j:used)j=-1;
		dfs(v);
	}
}

signed main () {
	int n, m, q;
	cin >> n >> m >> q;
	g.resize(n);
	used.resize(n, -1);
	rk.resize(n, 1);
	p.resize(n);
	for(int i = 0; i < n; i ++) p[i] = i;
	vector <pair <int,int>> edge;
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		edge.push_back({u-1, v-1});
	}
	vector <int> suff(m + 1);
	suff[m] = 0;
	for(int i = m - 1; i >= 0; i --) {
		if(suff[i+1] == 1) {
			suff[i] = suff[i+1]; 
			continue;
		}
		g[edge[i].first].push_back(edge[i].second);
		g[edge[i].second].push_back(edge[i].first);
		unite(edge[i].first, edge[i].second);
		f = 0;
		d(edge[i].first, edge[i].second);
		if(f) suff[i] = 1;
		else suff[i] = 0;
	}
	while(q --) {
		int l, r;
		cin >> l >> r;
		l --, r --;
		if(l == 0) {
			if(suff[r+1] == 1) cout << "YES\n";
			else cout << "NO\n";
			continue;
		}
		for(auto &i : g) i.clear();
		for(auto &i : used) i = -1;
		for(int i = 0; i < l; i ++) {
			g[edge[i].first].push_back(edge[i].second);
			g[edge[i].second].push_back(edge[i].first);
		}
		for(int i = r+1; i < m; i ++) {
			g[edge[i].first].push_back(edge[i].second);
			g[edge[i].second].push_back(edge[i].first);
		}
		for(int i = 0; i < n; i ++) {
			if(used[i]==-1) {
				f = 0;
				dfs(i);
				if(f) {
					cout << "YES\n";
					goto end;
				}
			}
		}
		cout << "NO\n";
		end:;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 56 ms 564 KB Output is correct
30 Correct 76 ms 604 KB Output is correct
31 Correct 81 ms 604 KB Output is correct
32 Correct 70 ms 712 KB Output is correct
33 Correct 59 ms 348 KB Output is correct
34 Correct 76 ms 604 KB Output is correct
35 Correct 107 ms 604 KB Output is correct
36 Correct 37 ms 548 KB Output is correct
37 Correct 84 ms 624 KB Output is correct
38 Correct 60 ms 604 KB Output is correct
39 Correct 75 ms 604 KB Output is correct
40 Correct 67 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 67 ms 344 KB Output is correct
43 Correct 66 ms 348 KB Output is correct
44 Correct 81 ms 344 KB Output is correct
45 Correct 102 ms 604 KB Output is correct
46 Correct 82 ms 604 KB Output is correct
47 Correct 67 ms 588 KB Output is correct
48 Correct 68 ms 344 KB Output is correct
49 Correct 76 ms 568 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 71 ms 344 KB Output is correct
52 Correct 76 ms 344 KB Output is correct
53 Correct 87 ms 572 KB Output is correct
54 Correct 93 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Execution timed out 2066 ms 8052 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Execution timed out 2066 ms 8052 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 56 ms 564 KB Output is correct
30 Correct 76 ms 604 KB Output is correct
31 Correct 81 ms 604 KB Output is correct
32 Correct 70 ms 712 KB Output is correct
33 Correct 59 ms 348 KB Output is correct
34 Correct 76 ms 604 KB Output is correct
35 Correct 107 ms 604 KB Output is correct
36 Correct 37 ms 548 KB Output is correct
37 Correct 84 ms 624 KB Output is correct
38 Correct 60 ms 604 KB Output is correct
39 Correct 75 ms 604 KB Output is correct
40 Correct 67 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 67 ms 344 KB Output is correct
43 Correct 66 ms 348 KB Output is correct
44 Correct 81 ms 344 KB Output is correct
45 Correct 102 ms 604 KB Output is correct
46 Correct 82 ms 604 KB Output is correct
47 Correct 67 ms 588 KB Output is correct
48 Correct 68 ms 344 KB Output is correct
49 Correct 76 ms 568 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 71 ms 344 KB Output is correct
52 Correct 76 ms 344 KB Output is correct
53 Correct 87 ms 572 KB Output is correct
54 Correct 93 ms 604 KB Output is correct
55 Execution timed out 2084 ms 8048 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 56 ms 564 KB Output is correct
30 Correct 76 ms 604 KB Output is correct
31 Correct 81 ms 604 KB Output is correct
32 Correct 70 ms 712 KB Output is correct
33 Correct 59 ms 348 KB Output is correct
34 Correct 76 ms 604 KB Output is correct
35 Correct 107 ms 604 KB Output is correct
36 Correct 37 ms 548 KB Output is correct
37 Correct 84 ms 624 KB Output is correct
38 Correct 60 ms 604 KB Output is correct
39 Correct 75 ms 604 KB Output is correct
40 Correct 67 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 67 ms 344 KB Output is correct
43 Correct 66 ms 348 KB Output is correct
44 Correct 81 ms 344 KB Output is correct
45 Correct 102 ms 604 KB Output is correct
46 Correct 82 ms 604 KB Output is correct
47 Correct 67 ms 588 KB Output is correct
48 Correct 68 ms 344 KB Output is correct
49 Correct 76 ms 568 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 71 ms 344 KB Output is correct
52 Correct 76 ms 344 KB Output is correct
53 Correct 87 ms 572 KB Output is correct
54 Correct 93 ms 604 KB Output is correct
55 Execution timed out 2066 ms 8052 KB Time limit exceeded
56 Halted 0 ms 0 KB -