File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
solution/3300-3399/3378.Count Connected Components in LCM Graph Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -32,15 +32,15 @@ typedef struct DSU {
32
32
33
33
class Solution {
34
34
public:
35
- int countComponents (vector<int > & nums, int threshold) {
35
+ int countComponents (vector<int >& nums, int threshold) {
36
36
DSU dsu (threshold);
37
- for (auto & num : nums) {
37
+ for (auto & num : nums) {
38
38
for (int j = num; j <= threshold; j += num) {
39
39
dsu.unionSet (num, j);
40
40
}
41
41
}
42
42
unordered_set<int > par;
43
- for (auto & num : nums) {
43
+ for (auto & num : nums) {
44
44
if (num > threshold) {
45
45
par.insert (num);
46
46
} else {
Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
private:
3
- void dfs (int node, vector<vector<int >> & adj, vector<bool > & vis) {
3
+ void dfs (int node, vector<vector<int >>& adj, vector<bool >& vis) {
4
4
if (vis[node]) return ;
5
5
vis[node] = true ;
6
- for (auto & u : adj[node]) {
6
+ for (auto & u : adj[node]) {
7
7
dfs (u, adj, vis);
8
8
}
9
9
}
10
10
11
11
public:
12
- int countComponents (vector<int > & nums, int threshold) {
12
+ int countComponents (vector<int >& nums, int threshold) {
13
13
vector<vector<int >> adj (threshold + 1 );
14
14
vector<bool > vis (threshold + 1 , false );
15
15
int ans = 0 ;
16
- for (auto & num : nums) {
16
+ for (auto & num : nums) {
17
17
if (num > threshold) {
18
18
++ans;
19
19
continue ;
@@ -23,7 +23,7 @@ class Solution {
23
23
adj[j].push_back (num);
24
24
}
25
25
}
26
- for (auto & num : nums) {
26
+ for (auto & num : nums) {
27
27
if (num <= threshold && !vis[num]) {
28
28
dfs (num, adj, vis);
29
29
++ans;
You can’t perform that action at this time.
0 commit comments