@Test public void testSuccessLogAtFinal() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(4, 2, 2)); logs.add(new SocialNetworkConn.Log(5, 0, 2)); Assert.assertEquals(5, SocialNetworkConn.earliestTimeToConnectAllMember(3, logs)); }
public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; }
SocialNetworkConn { public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; } }
SocialNetworkConn { public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; }  }
SocialNetworkConn { public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; }  static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog); }
SocialNetworkConn { public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; }  static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog);  }