G. Revolutionary Roads

Codeforces
IDCF10124G
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Governments of different countries like to boast about their achievements. For instance, the President of Flatland has announced that his country has the most advanced road system. He said the degree of a country road system development is equal to the amount of cities in the largest _connected_ subset of cities. A subset of cities is called _connected_ if it is possible to get from any city of the subset to all other cities of the subset. Not to lag behind the neighbors Berland's President decided to undertake a reform and modernize roads in his country. All the roads in Berland are one-way, each of them connects a pair of cities in one direction. There is at most one road in each direction between any two given cities. Since there is little money in the budget, President's plans aren't very ambitious. He can turn at most one of all given one-way roads into a two-way road. And he wants to do it in such a way that the resulting road system degree of development in Berland becomes as high as possible. Let's say the maximum degree of development, which can be achieved by this action, is equal to w. A road is called _revolutionary_ if, after it is changed from one-way to two-way, the degree of road system development becomes equal to w. Your task is to find all _revolutionary_ roads. The first line of input contains a pair of numbers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 20000), where n — the number cities, m — the number of roads. The following m lines contain descriptions of the roads. Each line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), representing a one-way road from city ai to city bi. Cities are numbered from 1 to n. Write w to the first line of output. To the second line write t — number of roads in the required subset. To the third line write indices of the roads in this subset. Roads are numbered from 1 to m according to their order in the input file. ## Input The first line of input contains a pair of numbers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 20000), where n — the number cities, m — the number of roads. The following m lines contain descriptions of the roads. Each line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), representing a one-way road from city ai to city bi. Cities are numbered from 1 to n. ## Output Write w to the first line of output. To the second line write t — number of roads in the required subset. To the third line write indices of the roads in this subset. Roads are numbered from 1 to m according to their order in the input file. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of cities, $ m \in \mathbb{Z}_{\geq 0} $ the number of directed roads. Let $ G = (V, E) $ be a directed graph with $ V = \{1, 2, \dots, n\} $ and $ E = \{(a_i, b_i) \mid i \in \{1, \dots, m\}\} $. Let $ \text{SCC}(G) $ denote the strongly connected components of $ G $. Let $ \text{cond}(G) $ denote the DAG of strongly connected components (condensation graph). **Constraints** 1. $ 1 \leq n \leq 1000 $ 2. $ 0 \leq m \leq 20000 $ 3. Each road is a directed edge $ (a_i, b_i) $ with $ a_i \ne b_i $, and no duplicate edges in same direction. **Objective** Let $ w $ be the maximum possible size of a strongly connected component achievable by reversing **at most one** directed edge in $ E $. A road $ e \in E $ is **revolutionary** if reversing $ e $ (making it bidirectional) results in a graph where the largest strongly connected component has size $ w $. Compute: 1. $ w $ 2. The number $ t $ of revolutionary roads 3. The indices (1-based) of all revolutionary roads **Output** - First line: $ w $ - Second line: $ t $ - Third line: sorted list of indices of revolutionary roads
API Response (JSON)
{
  "problem": {
    "name": "G. Revolutionary Roads",
    "description": {
      "content": "Governments of different countries like to boast about their achievements. For instance, the President of Flatland has announced that his country has the most advanced road system. He said the degree ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10124G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Governments of different countries like to boast about their achievements. For instance, the President of Flatland has announced that his country has the most advanced road system. He said the degree ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of cities, $ m \\in \\mathbb{Z}_{\\geq 0} $ the number of directed roads.  \nLet $ G = (V, E) $ be a directed graph with $ V = \\{1, 2, \\dots, n\\}...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments