Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
class Solution { public: vector
idx, sz; int root(int x) { while(x != idx[x]) { idx[x] = idx[idx[x]]; x = idx[x]; } return x; } void join(int a, int b) { int root_a = root(a); int root_b = root(b); if(root_a != root_b) { if(sz[root_a] > sz[root_b]) { idx[root_b] = idx[root_a]; sz[root_a] += sz[root_b]; } else { idx[root_a] = idx[root_b]; sz[root_b] += sz[root_a]; } } } int findCircleNum(vector
>& isConnected) { int n = (int) isConnected.size(); idx.resize(n); sz.resize(n); for(int i = 0; i < n; i++) { sz[i] = 1; idx[i] = i; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(isConnected[i][j] == 1) { join(i, j); } } } set
st; for(int i = 0; i < n; i++) { st.insert(root(i)); } return (int) st.size(); } };
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)