F. Simple Cycles Edges

Codeforces
IDCF962F
Time2000ms
Memory256MB
Difficulty
dfs and similargraphstrees
English · Original
Chinese · Translation
Formal · Original
You are given an undirected graph, consisting of $n$ vertices and $m$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself). A cycle in a graph is called a simple, if it contains each own vertex exactly once. So simple cycle doesn't allow to visit a vertex more than once in a cycle. Determine the edges, which belong to _exactly on one_ simple cycle. ## Input The first line contain two integers $n$ and $m$ $(1 \le n \le 100\,000$, $0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$ — the number of vertices and the number of edges. Each of the following $m$ lines contain two integers $u$ and $v$ ($1 \le u, v \le n$, $u \neq v$) — the description of the edges. ## Output In the first line print the number of edges, which belong to exactly one simple cycle. In the second line print the indices of edges, which belong to exactly one simple cycle, in **increasing** order. The edges are numbered from one in the same order as they are given in the input. [samples]
你被给定一个无向图,包含 $n$ 个顶点和 $m$ 条边。该图不一定连通。保证图中不含重边(顶点对之间多于一条边)或自环(从顶点到自身的边)。 图中的一个环被称为简单环,如果它恰好包含每个自身顶点一次。因此,简单环不允许在环中多次访问同一个顶点。 确定属于_恰好一个_简单环的边。 第一行包含两个整数 $n$ 和 $m$ $(1 lt.eq n lt.eq 100 thin 000$, $0 lt.eq m lt.eq min (n dot.op (n -1) \/ 2, 100 thin 000))$ —— 顶点数和边数。 接下来的 $m$ 行每行包含两个整数 $u$ 和 $v$ ($1 lt.eq u, v lt.eq n$, $u eq.not v$) —— 边的描述。 第一行输出属于恰好一个简单环的边的数量。 第二行按*递增*顺序输出属于恰好一个简单环的边的编号。边的编号从 1 开始,顺序与输入中给出的顺序一致。 ## Input 第一行包含两个整数 $n$ 和 $m$ $(1 lt.eq n lt.eq 100 thin 000$, $0 lt.eq m lt.eq min (n dot.op (n -1) \/ 2, 100 thin 000))$ —— 顶点数和边数。接下来的 $m$ 行每行包含两个整数 $u$ 和 $v$ ($1 lt.eq u, v lt.eq n$, $u eq.not v$) —— 边的描述。 ## Output 第一行输出属于恰好一个简单环的边的数量。第二行按*递增*顺序输出属于恰好一个简单环的边的编号。边的编号从 1 开始,顺序与输入中给出的顺序一致。 [samples]
**Definitions** Let $ G = (V, E) $ be an undirected graph with: - $ V = \{v_1, v_2, \dots, v_n\} $, $ |V| = n $, - $ E = \{e_1, e_2, \dots, e_m\} $, $ |E| = m $, where each edge $ e_i = \{u_i, v_i\} $, $ u_i \ne v_i $, and no multiple edges or loops. Let $ \mathcal{C} $ denote the set of all simple cycles in $ G $. For an edge $ e \in E $, define: $$ f(e) = \left| \{ C \in \mathcal{C} \mid e \in C \} \right| $$ i.e., the number of simple cycles containing edge $ e $. **Constraints** 1. $ 1 \le n \le 100{,}000 $ 2. $ 0 \le m \le \min\left( \frac{n(n-1)}{2}, 100{,}000 \right) $ 3. All edges are distinct and without self-loops. **Objective** Find the set: $$ E_{\text{unique}} = \{ e_i \in E \mid f(e_i) = 1 \} $$ Output: - $ |E_{\text{unique}}| $ - The indices $ i $ (in increasing order) such that $ e_i \in E_{\text{unique}} $, where edges are indexed from 1 in input order.
Samples
Input #1
3 3
1 2
2 3
3 1
Output #1
3
1 2 3
Input #2
6 7
2 3
3 4
4 2
1 2
1 5
5 6
6 1
Output #2
6
1 2 3 5 6 7
Input #3
5 6
1 2
2 3
2 4
4 3
2 5
5 3
Output #3
0
API Response (JSON)
{
  "problem": {
    "name": "F. Simple Cycles Edges",
    "description": {
      "content": "You are given an undirected graph, consisting of $n$ vertices and $m$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges b",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF962F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an undirected graph, consisting of $n$ vertices and $m$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges b...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "你被给定一个无向图,包含 $n$ 个顶点和 $m$ 条边。该图不一定连通。保证图中不含重边(顶点对之间多于一条边)或自环(从顶点到自身的边)。\n\n图中的一个环被称为简单环,如果它恰好包含每个自身顶点一次。因此,简单环不允许在环中多次访问同一个顶点。\n\n确定属于_恰好一个_简单环的边。 \n\n第一行包含两个整数 $n$ 和 $m$ $(1 lt.eq n lt.eq 100 thin 000$, $0...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ G = (V, E) $ be an undirected graph with:  \n- $ V = \\{v_1, v_2, \\dots, v_n\\} $, $ |V| = n $,  \n- $ E = \\{e_1, e_2, \\dots, e_m\\} $, $ |E| = m $, where each edge $ e_i = \\{u_i, v...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments