-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2685.cpp
More file actions
27 lines (24 loc) · 743 Bytes
/
Copy path2685.cpp
File metadata and controls
27 lines (24 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int countCompleteComponents(int n, const vector<vector<int>> &edges) {
static uint64_t con[50];
for (uint64_t i = 0; i < n; i++)
con[i] = 1ll << i;
for (const auto &edge : edges) {
con[edge[0]] |= 1ll << edge[1];
con[edge[1]] |= 1ll << edge[0];
}
int res = 0;
for (int i = 0; i < n; i++) {
if (!con[i]) continue;
for (uint64_t crnt = con[i] ^ (1ll << i), idx; crnt; crnt ^= 1ll << idx) {
idx = __builtin_ctzll(crnt);
if (con[idx] != con[i]) goto next;
con[idx] = 0;
}
res++;
next:;
}
return res;
}
};