@@ -0,0 +1,1179 @@
+public class FriendCircle %7B%0A%09public static void main(String%5B%5D args) %7B%0A%09%09char%5B%5D%5B%5D input = %7B%7B'Y', 'Y', 'N', 'N'%7D, %0A%09%09%09%09          %7B'Y', 'Y', 'Y', 'N'%7D,%0A%09%09%09%09          %7B'N', 'Y', 'Y', 'N'%7D,%0A%09%09%09%09          %7B'N', 'N', 'N', 'Y'%7D%7D;%0A%09%09int count = findFriendCircle(input);%0A%09%09System.out.println(count);%0A%09%7D%0A%09%0A%09public static int findFriendCircle(char%5B%5D%5B%5D input) %7B%0A%09%09if(input.length == 0 %7C%7C input%5B0%5D.length == 0)%0A%09%09  return 0;%0A%09%09%0A%09%09int n = input.length;%0A%09%09UnionFind uf = new UnionFind(n);%0A%09%09for(int i = 0; i %3C n - 1; i++) %7B%0A%09%09%09for(int j = i + 1; j %3C n; j++) %7B%0A%09%09%09%09if(input%5Bi%5D%5Bj%5D == 'Y') %0A%09%09%09%09  uf.union(i, j);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return uf.getCounts();%0A%09%7D%0A%7D%0A%0Aclass UnionFind %7B%0A%09int%5B%5D values;%0A%09int count;%0A%09%0A%09public UnionFind(int n)%7B%0A%09%09values = new int%5Bn%5D;%0A%09%09for(int i = 0; i %3C n; i++) %0A%09%09  values%5Bi%5D = i;%0A%09%09count = n;%0A%09%7D%0A%09%0A%09public void union(int x, int y) %7B%0A%09%09int valOfX = this.findRoot(x);%0A%09%09int valOfY = this.findRoot(y);%0A%09%09%0A%09%09if(valOfX != valOfY) %7B%0A%09%09%09this.values%5Bx%5D = valOfY;%0A%09%09%09this.count -= 1;%0A%09%09%7D%0A%09%7D%0A%09%0A%09public int findRoot(int x) %7B%0A%09%09int px = this.values%5Bx%5D;%0A%09%09if(px != x)%0A%09%09  this.values%5Bx%5D = this.findRoot(px);%0A%09%09return this.values%5Bx%5D;%0A%09%7D%0A%09%0A%09public int getCounts() %7B%0A%09%09return this.count;%0A%09%7D%0A%7D%0A

Create FriendCycle_001.java