Under construction

Still being built. Things may change

New Island

Time limit1sMemory limit128 MB

Summary
Given a graph whose edge i costs 2^i, delete the cheapest set of edges so the graph stays connected and every pairwise distance at most doubles.
Level

Hard8 of 10

Topics
Graph, Shortest path, Greedy, Implementation
Solved
No attempts yet

Problem

A new island has been discovered. A team of architects designed a road plan that connects the island's important places, but the budget is too small to build all of it, so the plan must be trimmed into a cheaper one.

In the proposed plan, every road has a distinct id between 11 and EE (where EE is the number of roads), and the road with id ii costs exactly 2i2^i. Because the ids are all different, the road costs are distinct powers of two.

We want to remove some roads so that the total cost of the remaining roads is as small as possible, while every place stays connected. However, roads may not be removed freely: in the reduced plan, the distance between any two places must not become more than twice their distance in the original plan. The distance between two places is the minimum number of roads on a route connecting them.

You are given the original road plan as a graph. Find the removal that minimizes the total remaining cost while respecting the distance constraint. Because the costs are distinct powers of two, this optimal removal is unique.

Input

The input contains several test cases. Each test case begins with a line containing two integers NN (1≤N≤2001 \le N \le 200) and EE — the number of places (vertices) and the number of roads (edges). Each of the next EE lines contains two integers viv_i and uiu_i, meaning the road with id ii runs between places viv_i and uiu_i (roads are numbered 11 through EE in the order they are given).

The input ends with a line containing two zeros.

Output

For each test case, print a single line containing the number of removed roads, followed by the ids of the removed roads in increasing order. If no road is removed, print a single 00.

Examples1

  1. Example 1

    Input
    4 5
    1 2
    3 1
    4 1
    4 2
    3 4
    3 3
    1 2
    2 3
    3 1
    0 0
    
    Expected output
    2 4 5
    1 3