Skip to content

Commit a9cd7a1

Browse files
Update cf-468B.mdx
1 parent 18b2a11 commit a9cd7a1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

solutions/gold/cf-468B.mdx

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ author: Chongtian Ma
66
---
77

88
<Spoiler title="Hint 1">
9+
910
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+
1012
</Spoiler>
1113

1214
<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+
1418
</Spoiler>
1519

1620
## Explanation
@@ -24,14 +28,13 @@ We can treat each set as a graph with several connected components. For each $p_
2428
**Time Complexity:** $\mathcal{O}(N\log N)$
2529

2630
<LanguageSection>
27-
2831
<CPPSection>
2932

3033
```cpp
3134
#include <bits/stdc++.h>
3235
using namespace std;
3336

34-
// BeginCodeSnip{Disjoint Set Union}
37+
// BeginCodeSnip{DSU}
3538
struct DSU {
3639
vector<int> e;
3740
DSU(int N) { e = vector<int>(N, -1); }
@@ -75,6 +78,7 @@ int main() {
7578
dsu.unite(i, at[b - p[i]]);
7679
}
7780
}
81+
7882
/*
7983
* first bit activated if all numbers in component i can reside in
8084
* graph A, and similarly the second bit for graph B
@@ -86,12 +90,14 @@ int main() {
8690
if (can_B[i]) mask += 2;
8791
can_component[dsu.get(i)] &= mask;
8892
}
93+
8994
for (int i = 0; i < n; i++) {
9095
if (!can_component[i]) {
9196
cout << "NO" << endl;
9297
return 0;
9398
}
9499
}
100+
95101
cout << "YES" << endl;
96102
for (int i = 0; i < n; i++) {
97103
int comp_mask = can_component[dsu.get(i)];
@@ -108,5 +114,4 @@ int main() {
108114
```
109115
110116
</CPPSection>
111-
112117
</LanguageSection>

0 commit comments

Comments
 (0)