File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,15 @@ author: Chongtian Ma
6
6
---
7
7
8
8
<Spoiler title = " Hint 1" >
9
+
9
10
We can model the two sets as a graph, with $p_i$ and $a - p_i$ connected in graph $A$, and $p_i$ connected to $b - p_i$ in graph B.
11
+
10
12
</Spoiler >
11
13
12
14
<Spoiler title = " Hint 2" >
13
- How is there a contradiction in the connected components?
15
+
16
+ How can there be a contradiction in the connected components?
17
+
14
18
</Spoiler >
15
19
16
20
## Explanation
@@ -24,14 +28,13 @@ We can treat each set as a graph with several connected components. For each $p_
24
28
** Time Complexity:** $\mathcal{ O } (N\log N)$
25
29
26
30
<LanguageSection >
27
-
28
31
<CPPSection >
29
32
30
33
``` cpp
31
34
#include < bits/stdc++.h>
32
35
using namespace std ;
33
36
34
- // BeginCodeSnip{Disjoint Set Union }
37
+ // BeginCodeSnip{DSU }
35
38
struct DSU {
36
39
vector < int > e ;
37
40
DSU (int N ) { e = vector <int >(N , - 1 ); }
@@ -75,6 +78,7 @@ int main() {
75
78
dsu .unite (i , at [b - p [i ]]);
76
79
}
77
80
}
81
+
78
82
/*
79
83
* first bit activated if all numbers in component i can reside in
80
84
* graph A, and similarly the second bit for graph B
@@ -86,12 +90,14 @@ int main() {
86
90
if (can_B [i ]) mask += 2 ;
87
91
can_component [dsu .get (i )] &= mask ;
88
92
}
93
+
89
94
for (int i = 0 ; i < n ; i ++) {
90
95
if (! can_component [i ]) {
91
96
cout << " NO" << endl ;
92
97
return 0 ;
93
98
}
94
99
}
100
+
95
101
cout << " YES" << endl ;
96
102
for (int i = 0 ; i < n ; i ++) {
97
103
int comp_mask = can_component [dsu .get (i )];
@@ -108,5 +114,4 @@ int main() {
108
114
` ` `
109
115
110
116
</CPPSection>
111
-
112
117
</LanguageSection>
You can’t perform that action at this time.
0 commit comments