QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#17230. 最小哈希

Estadísticas

考虑一个无向简单图 $G = (V, E)$。寻找具有相似连接性的节点是一个被广泛研究的课题,因为它可以作为衡量哪些节点与其他节点相关的良好指标。Facebook 中的“好友推荐”等服务就是其应用的一个很好例子。 为了使相似性的概念形式化,可以使用 Jaccard 相似度的概念,其定义为 $|N(v_1) \cap N(v_2)|/|N(v_1) \cup N(v_2)|$,其中 $N(v) = \{u \mid (u, v) \in E\}$。

在这里,我们将讨论最小哈希(min-hashing)方法。假设每个节点 $v$ 都有一个标签 $l_v$。节点 $v$ 的 shingle 值 $s_v$ 定义为 $s_v = \min\{l_u \mid u \in N(v)\}$。这种方法足够高效,可以满足工业界的需求,同时它也是一个很好的相似度度量:对于随机的唯一标签,邻居集合 $N(v_1)$ 和 $N(v_2)$ 之间的 Jaccard 相似度是节点 $v_1$ 和 $v_2$ 具有相同 shingle 值的概率的无偏估计。

让我们考虑最小哈希的一个变体:我们通过将上一次迭代的 shingle 值作为标签,来重复进行最小哈希。在这种变体中,对于每个节点 $v$ 和迭代次数 $k$,值 $h_v^{(k)}$ 定义为:

$$h_v^{(k)} = \begin{cases} s_v, & \text{if } k = 1 \\ \min\{h_u^{(k-1)} \mid u \in N(v)\}, & \text{if } k \ge 2 \end{cases}$$

对于每个 $k$,令 $c_k$ 为满足 $h_u^{(k)} = h_v^{(k)}$ 的无序不同顶点对 $\{u, v\}$ 的数量。那么,随着 $k$ 的增加,$c_k$ 的值会如何变化?在本题中,你的任务是计算 $\max_{k \in \mathbb{N}} c_k$。

输入格式

第一行包含两个正整数 $n$ 和 $m$($1 \le n \le 100\,000$,$1 \le m \le 250\,000$),分别表示节点数和边数。节点编号为 $1$ 到 $n$。注意,这些编号不是节点的标签。

第二行包含 $n$ 个整数,构成前 $n$ 个正整数的一个排列,其中第 $i$ 个数字表示节点 $i$ 的初始标签。

接下来的 $m$ 行,每行包含两个整数。其中第 $i$ 行包含两个不同的整数 $u_i$ 和 $v_i$($1 \le u_i, v_i \le n$),表示 $\{u_i, v_i\} \in E$。

输入数据的构造保证图中不存在自环、重边或度数为零的节点。

输出格式

输出 $c_k$ 在所有正整数 $k$ 上的最大值。

样例

输入样例 1

5 5
1 2 3 4 5
1 2
2 3
3 4
4 5
5 1

输出样例 1

10

输入样例 2

4 3
1 2 3 4
1 2
2 3
3 4

输出样例 2

2

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.