Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void union(int s, int t){
- List<Set<Integer>> hack = new LinkedList<>();
- for (Set<Integer> e : list) {
- Set<Integer> union = new HashSet<>();
- if(e.contains(s) && !e.contains(t)) {
- union.addAll(e);
- union.add(t);
- e.clear();
- }else if(e.contains(t) && !e.contains(s)) {
- union.addAll(e);
- union.add(s);
- e.clear();
- }
- hack.add(union);
- }
- list.addAll(hack);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement