답안 #858781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858781 2023-10-09T07:41:43 Z maks007 Joker (BOI20_joker) C++14
14 / 100
2000 ms 7536 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] && get(u) == get(v)) 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 1 ms 344 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 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 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 344 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 2 ms 348 KB Output is correct
20 Correct 1 ms 348 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 348 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 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 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 344 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 2 ms 348 KB Output is correct
20 Correct 1 ms 348 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 348 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 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 55 ms 348 KB Output is correct
30 Correct 75 ms 600 KB Output is correct
31 Correct 83 ms 604 KB Output is correct
32 Correct 68 ms 348 KB Output is correct
33 Correct 59 ms 344 KB Output is correct
34 Correct 75 ms 604 KB Output is correct
35 Correct 88 ms 600 KB Output is correct
36 Correct 38 ms 348 KB Output is correct
37 Correct 76 ms 600 KB Output is correct
38 Correct 63 ms 604 KB Output is correct
39 Correct 67 ms 604 KB Output is correct
40 Correct 69 ms 344 KB Output is correct
41 Correct 66 ms 344 KB Output is correct
42 Correct 73 ms 588 KB Output is correct
43 Correct 72 ms 348 KB Output is correct
44 Correct 78 ms 348 KB Output is correct
45 Correct 81 ms 348 KB Output is correct
46 Correct 91 ms 604 KB Output is correct
47 Correct 64 ms 344 KB Output is correct
48 Correct 75 ms 348 KB Output is correct
49 Correct 78 ms 572 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 70 ms 348 KB Output is correct
52 Correct 75 ms 348 KB Output is correct
53 Correct 81 ms 344 KB Output is correct
54 Correct 86 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2023 ms 7508 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 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 344 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 2 ms 348 KB Output is correct
20 Correct 1 ms 348 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 348 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 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 2023 ms 7508 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 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 344 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 2 ms 348 KB Output is correct
20 Correct 1 ms 348 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 348 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 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 55 ms 348 KB Output is correct
30 Correct 75 ms 600 KB Output is correct
31 Correct 83 ms 604 KB Output is correct
32 Correct 68 ms 348 KB Output is correct
33 Correct 59 ms 344 KB Output is correct
34 Correct 75 ms 604 KB Output is correct
35 Correct 88 ms 600 KB Output is correct
36 Correct 38 ms 348 KB Output is correct
37 Correct 76 ms 600 KB Output is correct
38 Correct 63 ms 604 KB Output is correct
39 Correct 67 ms 604 KB Output is correct
40 Correct 69 ms 344 KB Output is correct
41 Correct 66 ms 344 KB Output is correct
42 Correct 73 ms 588 KB Output is correct
43 Correct 72 ms 348 KB Output is correct
44 Correct 78 ms 348 KB Output is correct
45 Correct 81 ms 348 KB Output is correct
46 Correct 91 ms 604 KB Output is correct
47 Correct 64 ms 344 KB Output is correct
48 Correct 75 ms 348 KB Output is correct
49 Correct 78 ms 572 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 70 ms 348 KB Output is correct
52 Correct 75 ms 348 KB Output is correct
53 Correct 81 ms 344 KB Output is correct
54 Correct 86 ms 604 KB Output is correct
55 Execution timed out 2012 ms 7536 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 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 344 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 2 ms 348 KB Output is correct
20 Correct 1 ms 348 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 348 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 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 55 ms 348 KB Output is correct
30 Correct 75 ms 600 KB Output is correct
31 Correct 83 ms 604 KB Output is correct
32 Correct 68 ms 348 KB Output is correct
33 Correct 59 ms 344 KB Output is correct
34 Correct 75 ms 604 KB Output is correct
35 Correct 88 ms 600 KB Output is correct
36 Correct 38 ms 348 KB Output is correct
37 Correct 76 ms 600 KB Output is correct
38 Correct 63 ms 604 KB Output is correct
39 Correct 67 ms 604 KB Output is correct
40 Correct 69 ms 344 KB Output is correct
41 Correct 66 ms 344 KB Output is correct
42 Correct 73 ms 588 KB Output is correct
43 Correct 72 ms 348 KB Output is correct
44 Correct 78 ms 348 KB Output is correct
45 Correct 81 ms 348 KB Output is correct
46 Correct 91 ms 604 KB Output is correct
47 Correct 64 ms 344 KB Output is correct
48 Correct 75 ms 348 KB Output is correct
49 Correct 78 ms 572 KB Output is correct
50 Correct 78 ms 344 KB Output is correct
51 Correct 70 ms 348 KB Output is correct
52 Correct 75 ms 348 KB Output is correct
53 Correct 81 ms 344 KB Output is correct
54 Correct 86 ms 604 KB Output is correct
55 Execution timed out 2023 ms 7508 KB Time limit exceeded
56 Halted 0 ms 0 KB -