class ArbitraryMatching {

    static int initial(final Graph g, Matching m, final BitSet s) {

        int nMatched = 0;

        for (int v = s.nextSetBit(0); v >= 0; v = s.nextSetBit(v + 1)) {

            // skip if already matched
            if (m.matched(v))
                continue;

            // find a single edge which is not matched and match it
            int d = g.degree(v);
            for (int j = 0; j < d; ++j) {
                Edge e = g.edgeAt(v, j);
                int w = e.other(v);
                if ((e.bond() != Bond.SINGLE) && m.unmatched(w) && s.get(w)) {
                    m.match(v, w);
                    nMatched += 2;
                    break;
                }
            }
        }

        return nMatched;
    }

}