QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#4085. 通信网

统计

通信网由 $N$ 个计算机和 $M$ 条线路组成。计算机编号从 $1$ 到 $N$。每一条线路使两台不同的计算机能够双向通信。如果通信网中任意两台计算机都能通过一条或多条线路进行通信,则称该通信网是连通的。如果存在无法通信的计算机对,则称该通信网是断开的。

通信网中某条线路 $c$ 的危险度定义如下:

  • 对于通信网中的每台计算机 $i$,如果移除计算机 $i$ 后剩余的通信网是断开的,则称计算机 $i$ 为危险计算机。
  • 在初始通信网中移除 $c$ 后,危险计算机的数量定义为 $c$ 的危险度。

请编写一个程序,输入通信网并计算每条线路的危险度。

实现细节

你需要实现以下函数:

vector<int> find_num_critical(int N, vector< pair<int, int> > E)
  • 该函数仅被调用一次。
  • 参数 $N$ 表示计算机的数量。
  • 参数数组 $E$ 的大小为 $M$。数组 $E$ 的每个元素代表一条线路,由一对不同的计算机编号给出。
  • 该函数需要计算每条线路的危险度,并将其存入一个长度为 $M$ 的整数数组中返回。数组中各危险度对应的线路顺序应与参数 $E$ 给出的顺序一致。

提交的源代码中不得在任何部分执行输入输出函数。

数据范围

  • $2 \le N \le 250\,000$
  • $1 \le M \le 1\,000\,000$
  • 每条线路连接两台不同的计算机。
  • 连接同一对计算机的线路可能有多条。
  • 初始通信网是连通的。

子任务

  1. (5分) $N \le 200$, $M \le 500$
  2. (11分) $N \le 1\,000$, $M \le 2\,500$
  3. (7分) $N = M$
  4. (13分) 对于 $k \ge 2$ 台不同的计算机 $v_1, v_2, \dots, v_k$ 和 $k$ 条不同的线路 $c_1, c_2, \dots, c_k$,若线路 $c_i$ 连接两台计算机 $v_i, v_{i+1}$ ($1 \le i \le k-1$),且线路 $c_k$ 连接两台计算机 $v_k, v_1$,则称这 $k$ 条线路 $c_1, c_2, \dots, c_k$ 构成一个环。两个环相同意味着构成环的线路集合相同。 通信网中每条线路 $c$,包含该线路的环最多存在一个。
  5. (25分) $N \le 8\,000$, $M \le 250\,000$
  6. (29分) $N \le 100\,000$, $M \le 250\,000$
  7. (10分) 无额外限制。

评分标准

只有当 find_num_critical 函数返回的序列长度为 $M$,且返回序列的元素与正确答案序列完全一致时,该测试数据才会被判定为正确。

样例

考虑 $N = 5$ 且线路 $E = [ [1, 5], [5, 2], [2, 3], [2, 4], [2, 5] ]$ 的情况。 评测程序调用以下函数:

find_num_critical(5, [ [1, 5], [5, 2], [2, 3], [2, 4], [2, 5] ])

初始通信网如下所示:

例如,移除连接 1 号和 5 号计算机的线路后,通信网变为如下所示:

在此通信网中,危险计算机为 2, 3, 4, 5 号。注意,1 号计算机移除后剩余通信网仍是连通的,因此它不是危险计算机。

移除连接 2 号和 5 号计算机的其中一条线路后,通信网变为如下所示:

在此通信网中,危险计算机为 2 号和 5 号。

find_num_critical 函数应返回序列 $[4, 2, 4, 4, 2]$。 该样例满足所有子任务的条件。

Sample grader

Sample grader 按以下格式接收输入:

  • Line 1: $N, M$
  • Line $1 + i$ ($1 \le i \le M$): $a_i, b_i$

$a_i, b_i$ 对表示 $a_i$ 号和 $b_i$ 号计算机由一条线路连接 ($1 \le i \le M$)。

Sample grader 输出以下内容:

  • Line 1: 函数 find_num_critical 返回的数组

请注意,Sample grader 可能与实际评测中使用的评测程序不同。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.