// Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
// public class Bag<T extends Comparable<T>> implements Iterable<T> {
//     private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
//     private Node<T> head;
//     private int size;
// 
//     /**
//      * Adds the item to the bag.
//      *
//      * @param item to be added
//      * @throws IllegalArgumentException when item is null
//      */
//     public void add(T item) throws IllegalArgumentException {
//         if (item == null)
//             throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
// 
//         Node<T> node = new Node<>(item);
//         Node<T> next = head;
//         head = node;
//         head.next = next;
// 
//         if (next != null)
//             next.prev = head;
// 
//         size++;
//     }
// 
//     /**
//      * Returns whether the bag is empty or not.
//      *
//      * @return whether the bag is empty or not
//      */
//     public boolean isEmpty() {
//         return size == 0;
//     }
// 
//     /**
//      * Returns the number of items in the bag.
//      *
//      * @return number of items in the bag
//      */
//     public int size() {
//         return size;
//     }
// 
//     @Override
//     public Iterator<T> iterator() {
//         return new LinkedListIterator(head);
//     }
// }


import io.github.marioluan.datastructures.multiset.Bag;
import java.util.stream.IntStream;
package io.github.marioluan.datastructures.graph;



/**
 * Undirected {@link Graph} implementation using an adjacency-list.<br>
 * Maintain vertex-indexed array of lists.<br>
 * <b>Space complexity: E + V</b>
 */
public class Undirected implements Graph {
    private final int V;
// Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
// public class Bag<T extends Comparable<T>> implements Iterable<T> {
//     private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
//     private Node<T> head;
//     private int size;
// 
//     /**
//      * Adds the item to the bag.
//      *
//      * @param item to be added
//      * @throws IllegalArgumentException when item is null
//      */
//     public void add(T item) throws IllegalArgumentException {
//         if (item == null)
//             throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
// 
//         Node<T> node = new Node<>(item);
//         Node<T> next = head;
//         head = node;
//         head.next = next;
// 
//         if (next != null)
//             next.prev = head;
// 
//         size++;
//     }
// 
//     /**
//      * Returns whether the bag is empty or not.
//      *
//      * @return whether the bag is empty or not
//      */
//     public boolean isEmpty() {
//         return size == 0;
//     }
// 
//     /**
//      * Returns the number of items in the bag.
//      *
//      * @return number of items in the bag
//      */
//     public int size() {
//         return size;
//     }
// 
//     @Override
//     public Iterator<T> iterator() {
//         return new LinkedListIterator(head);
//     }
// }


// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
import io.github.marioluan.datastructures.multiset.Bag;
import java.util.stream.IntStream;

package io.github.marioluan.datastructures.graph;



/**
 * Undirected {@link Graph} implementation using an adjacency-list.<br>
 * Maintain vertex-indexed array of lists.<br>
 * <b>Space complexity: E + V</b>
 */
public class Undirected implements Graph {
    private final int V;
    private int E;