답안 #256181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256181 2020-08-02T11:02:21 Z gs14004 Joker (BOI20_joker) C++17
100 / 100
639 ms 71368 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 400005;

struct event{
	int *p;
	int v;
};

int n, m, q;
pi a[MAXN];

void rollback(vector<event> &E){
	reverse(all(E));
	for(auto &i : E){
		*i.p = i.v;
	}
	E.clear();
}

struct btracker{
	int pa[MAXN], rk[MAXN];
	int is_cycle;
	void init(int n){
		iota(pa, pa + n + 1, 0);
		memset(rk, 0, sizeof(rk));
		is_cycle = 0;
	}
	int find(int x){
		return pa[x] == x ? x : find(pa[x]);
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		if(rk[p] > rk[q]) swap(p, q);
		pa[p] = q;
		if(rk[p] == rk[q]) rk[q]++;
		return 1;
	}
	bool uni(int p, int q, vector<event> &snap){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		if(rk[p] > rk[q]) swap(p, q);
		snap.push_back((event){&pa[p], pa[p]});
		pa[p] = q;
		if(rk[p] == rk[q]){
			snap.push_back((event){&rk[q], rk[q]});
			rk[q]++;
		}
		return 1;
	}
	void add_edge(int x, int y){
		uni(x, y + n);
		uni(y, x + n);
		if(find(x) == find(x + n)) is_cycle = 1;
	}
	void add_edge(int x, int y, vector<event> &snap){
		uni(x, y + n, snap);
		uni(y, x + n, snap);
		if(find(x) == find(x + n)){
			snap.push_back((event){&is_cycle, is_cycle});
			is_cycle = 1;
		}
	}
}disj;

int dap[MAXN];

void solve(int s, int e, int ps, int pe){
	if(s > e) return;
	int m = (s + e) / 2;
	vector<event> snap1, snap2;
	for(int i = e; i >= m; i--){
		disj.add_edge(a[i].first, a[i].second, snap1);
	}
	for(int i = ps; i <= pe; i++){
		disj.add_edge(a[i].first, a[i].second, snap2);
		if(disj.is_cycle){
			dap[m] = i;
			break;
		}
	}
	rollback(snap2);
	solve(s, m - 1, ps, dap[m]);
	rollback(snap1);
	for(int i = ps; i <= dap[m] - 1; i++){
		disj.add_edge(a[i].first, a[i].second, snap1);
	}
	solve(m + 1, e, dap[m], pe);
	rollback(snap1);
}

int main(){
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1; i<=m; i++){
		scanf("%d %d",&a[i].first,&a[i].second);
		a[i + m] = a[i];
	}
	disj.init(n+n);
	int stpos = -1;
	for(int i=m; i; i--){
		disj.add_edge(a[i].first, a[i].second);
		if(disj.is_cycle){
			stpos = i + 1;
			break;
		}
	}
	if(disj.is_cycle == 0){
		while(q--) puts("NO");
		return 0;
	}
	disj.init(n+n);
	{
		vector<event> v;
		dap[m + 1] = 2 * m + 1;
		for(int j=m + 1; j<=2*m; j++){
			disj.add_edge(a[j].first, a[j].second, v);
			if(disj.is_cycle){
				dap[m + 1] = j;
				break;
			}
		}
		rollback(v);
	}
	solve(stpos, m, m + 1, dap[m + 1]);
	while(q--){
		int x, y; scanf("%d %d",&x,&y);
		if(y + 1 < stpos) puts("YES");
		else puts(dap[y + 1] < x + m? "YES" : "NO");
	}
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
Joker.cpp:103:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].first,&a[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:134:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d %d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 1 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 1 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 4 ms 2176 KB Output is correct
31 Correct 6 ms 2136 KB Output is correct
32 Correct 5 ms 2048 KB Output is correct
33 Correct 3 ms 2048 KB Output is correct
34 Correct 4 ms 2176 KB Output is correct
35 Correct 5 ms 2176 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 5 ms 2176 KB Output is correct
38 Correct 3 ms 1920 KB Output is correct
39 Correct 4 ms 2176 KB Output is correct
40 Correct 3 ms 2176 KB Output is correct
41 Correct 4 ms 2176 KB Output is correct
42 Correct 4 ms 2176 KB Output is correct
43 Correct 4 ms 2048 KB Output is correct
44 Correct 4 ms 2048 KB Output is correct
45 Correct 4 ms 2176 KB Output is correct
46 Correct 5 ms 2176 KB Output is correct
47 Correct 4 ms 2048 KB Output is correct
48 Correct 4 ms 2048 KB Output is correct
49 Correct 5 ms 2304 KB Output is correct
50 Correct 5 ms 2176 KB Output is correct
51 Correct 4 ms 2048 KB Output is correct
52 Correct 4 ms 2136 KB Output is correct
53 Correct 5 ms 2176 KB Output is correct
54 Correct 6 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 302 ms 12928 KB Output is correct
4 Correct 72 ms 7160 KB Output is correct
5 Correct 238 ms 24504 KB Output is correct
6 Correct 275 ms 24832 KB Output is correct
7 Correct 317 ms 23056 KB Output is correct
8 Correct 304 ms 16144 KB Output is correct
9 Correct 326 ms 17768 KB Output is correct
10 Correct 458 ms 27988 KB Output is correct
11 Correct 325 ms 17912 KB Output is correct
12 Correct 417 ms 25572 KB Output is correct
13 Correct 237 ms 9640 KB Output is correct
14 Correct 342 ms 16000 KB Output is correct
15 Correct 410 ms 21492 KB Output is correct
16 Correct 479 ms 27856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 1 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 302 ms 12928 KB Output is correct
30 Correct 72 ms 7160 KB Output is correct
31 Correct 238 ms 24504 KB Output is correct
32 Correct 275 ms 24832 KB Output is correct
33 Correct 317 ms 23056 KB Output is correct
34 Correct 304 ms 16144 KB Output is correct
35 Correct 326 ms 17768 KB Output is correct
36 Correct 458 ms 27988 KB Output is correct
37 Correct 325 ms 17912 KB Output is correct
38 Correct 417 ms 25572 KB Output is correct
39 Correct 237 ms 9640 KB Output is correct
40 Correct 342 ms 16000 KB Output is correct
41 Correct 410 ms 21492 KB Output is correct
42 Correct 479 ms 27856 KB Output is correct
43 Correct 297 ms 13024 KB Output is correct
44 Correct 72 ms 7160 KB Output is correct
45 Correct 402 ms 31048 KB Output is correct
46 Correct 268 ms 28092 KB Output is correct
47 Correct 294 ms 23500 KB Output is correct
48 Correct 384 ms 17904 KB Output is correct
49 Correct 450 ms 29632 KB Output is correct
50 Correct 302 ms 14892 KB Output is correct
51 Correct 330 ms 18436 KB Output is correct
52 Correct 389 ms 22052 KB Output is correct
53 Correct 243 ms 10024 KB Output is correct
54 Correct 332 ms 18320 KB Output is correct
55 Correct 425 ms 20976 KB Output is correct
56 Correct 429 ms 29632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 1 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 4 ms 2176 KB Output is correct
31 Correct 6 ms 2136 KB Output is correct
32 Correct 5 ms 2048 KB Output is correct
33 Correct 3 ms 2048 KB Output is correct
34 Correct 4 ms 2176 KB Output is correct
35 Correct 5 ms 2176 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 5 ms 2176 KB Output is correct
38 Correct 3 ms 1920 KB Output is correct
39 Correct 4 ms 2176 KB Output is correct
40 Correct 3 ms 2176 KB Output is correct
41 Correct 4 ms 2176 KB Output is correct
42 Correct 4 ms 2176 KB Output is correct
43 Correct 4 ms 2048 KB Output is correct
44 Correct 4 ms 2048 KB Output is correct
45 Correct 4 ms 2176 KB Output is correct
46 Correct 5 ms 2176 KB Output is correct
47 Correct 4 ms 2048 KB Output is correct
48 Correct 4 ms 2048 KB Output is correct
49 Correct 5 ms 2304 KB Output is correct
50 Correct 5 ms 2176 KB Output is correct
51 Correct 4 ms 2048 KB Output is correct
52 Correct 4 ms 2136 KB Output is correct
53 Correct 5 ms 2176 KB Output is correct
54 Correct 6 ms 2176 KB Output is correct
55 Correct 243 ms 13028 KB Output is correct
56 Correct 66 ms 6520 KB Output is correct
57 Correct 142 ms 16056 KB Output is correct
58 Correct 247 ms 31164 KB Output is correct
59 Correct 291 ms 18508 KB Output is correct
60 Correct 343 ms 18972 KB Output is correct
61 Correct 257 ms 18032 KB Output is correct
62 Correct 322 ms 31812 KB Output is correct
63 Correct 215 ms 13696 KB Output is correct
64 Correct 342 ms 18868 KB Output is correct
65 Correct 398 ms 21120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 1 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 4 ms 2176 KB Output is correct
31 Correct 6 ms 2136 KB Output is correct
32 Correct 5 ms 2048 KB Output is correct
33 Correct 3 ms 2048 KB Output is correct
34 Correct 4 ms 2176 KB Output is correct
35 Correct 5 ms 2176 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 5 ms 2176 KB Output is correct
38 Correct 3 ms 1920 KB Output is correct
39 Correct 4 ms 2176 KB Output is correct
40 Correct 3 ms 2176 KB Output is correct
41 Correct 4 ms 2176 KB Output is correct
42 Correct 4 ms 2176 KB Output is correct
43 Correct 4 ms 2048 KB Output is correct
44 Correct 4 ms 2048 KB Output is correct
45 Correct 4 ms 2176 KB Output is correct
46 Correct 5 ms 2176 KB Output is correct
47 Correct 4 ms 2048 KB Output is correct
48 Correct 4 ms 2048 KB Output is correct
49 Correct 5 ms 2304 KB Output is correct
50 Correct 5 ms 2176 KB Output is correct
51 Correct 4 ms 2048 KB Output is correct
52 Correct 4 ms 2136 KB Output is correct
53 Correct 5 ms 2176 KB Output is correct
54 Correct 6 ms 2176 KB Output is correct
55 Correct 302 ms 12928 KB Output is correct
56 Correct 72 ms 7160 KB Output is correct
57 Correct 238 ms 24504 KB Output is correct
58 Correct 275 ms 24832 KB Output is correct
59 Correct 317 ms 23056 KB Output is correct
60 Correct 304 ms 16144 KB Output is correct
61 Correct 326 ms 17768 KB Output is correct
62 Correct 458 ms 27988 KB Output is correct
63 Correct 325 ms 17912 KB Output is correct
64 Correct 417 ms 25572 KB Output is correct
65 Correct 237 ms 9640 KB Output is correct
66 Correct 342 ms 16000 KB Output is correct
67 Correct 410 ms 21492 KB Output is correct
68 Correct 479 ms 27856 KB Output is correct
69 Correct 297 ms 13024 KB Output is correct
70 Correct 72 ms 7160 KB Output is correct
71 Correct 402 ms 31048 KB Output is correct
72 Correct 268 ms 28092 KB Output is correct
73 Correct 294 ms 23500 KB Output is correct
74 Correct 384 ms 17904 KB Output is correct
75 Correct 450 ms 29632 KB Output is correct
76 Correct 302 ms 14892 KB Output is correct
77 Correct 330 ms 18436 KB Output is correct
78 Correct 389 ms 22052 KB Output is correct
79 Correct 243 ms 10024 KB Output is correct
80 Correct 332 ms 18320 KB Output is correct
81 Correct 425 ms 20976 KB Output is correct
82 Correct 429 ms 29632 KB Output is correct
83 Correct 243 ms 13028 KB Output is correct
84 Correct 66 ms 6520 KB Output is correct
85 Correct 142 ms 16056 KB Output is correct
86 Correct 247 ms 31164 KB Output is correct
87 Correct 291 ms 18508 KB Output is correct
88 Correct 343 ms 18972 KB Output is correct
89 Correct 257 ms 18032 KB Output is correct
90 Correct 322 ms 31812 KB Output is correct
91 Correct 215 ms 13696 KB Output is correct
92 Correct 342 ms 18868 KB Output is correct
93 Correct 398 ms 21120 KB Output is correct
94 Correct 317 ms 13200 KB Output is correct
95 Correct 639 ms 71368 KB Output is correct
96 Correct 230 ms 18744 KB Output is correct
97 Correct 305 ms 26172 KB Output is correct
98 Correct 325 ms 24660 KB Output is correct
99 Correct 303 ms 14732 KB Output is correct
100 Correct 496 ms 42980 KB Output is correct
101 Correct 330 ms 15144 KB Output is correct
102 Correct 350 ms 18296 KB Output is correct
103 Correct 407 ms 22924 KB Output is correct
104 Correct 289 ms 13996 KB Output is correct
105 Correct 389 ms 20272 KB Output is correct
106 Correct 447 ms 20504 KB Output is correct
107 Correct 257 ms 16840 KB Output is correct
108 Correct 320 ms 13036 KB Output is correct
109 Correct 317 ms 12944 KB Output is correct
110 Correct 315 ms 12944 KB Output is correct
111 Correct 343 ms 12944 KB Output is correct
112 Correct 312 ms 12944 KB Output is correct
113 Correct 342 ms 12948 KB Output is correct
114 Correct 350 ms 12944 KB Output is correct
115 Correct 337 ms 13072 KB Output is correct
116 Correct 323 ms 13200 KB Output is correct