QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#2827. 自传

Estadísticas

Bobo 有一个包含 $n$ 个顶点和 $m$ 条边的无向图。顶点编号为 $1, \dots, n$,第 $i$ 条边连接 $a_i$ 和 $b_i$ 号顶点。此外,第 $i$ 个顶点关联一个字符 $c_i$。

请找出选择四个不同顶点 $(u, v, w, x)$ 的方案数,使得: $u$ 和 $v$、 $v$ 和 $w$、 $w$ 和 $x$ 之间均有边相连, $c_u = \text{'b'}, c_v = \text{'o'}, c_w = \text{'b'}, c_x = \text{'o'}$。

输入格式

输入包含多组测试数据,以文件结束符(EOF)结束。对于每组测试数据:

第一行包含两个整数 $n$ 和 $m$。 第二行包含 $n$ 个字符 $c_1 \dots c_n$。 接下来的 $m$ 行中,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$。

  • $4 \le n \le 2 \times 10^5$
  • $0 \le m \le 2 \times 10^5$
  • $c_i \in \{\text{'b'}, \text{'o'}\}$,对于每个 $1 \le i \le n$
  • $1 \le a_i, b_i \le n$,对于每个 $1 \le i \le m$
  • $a_i \neq b_i$,对于每个 $1 \le i \le m$
  • $\{a_i, b_i\} \neq \{a_j, b_j\}$,对于每个 $1 \le i < j \le m$
  • 在每组输入中,$n$ 的总和不超过 $2 \times 10^5$,$m$ 的总和不超过 $2 \times 10^5$。

输出格式

对于每组测试数据,输出一个整数,表示方案数。

样例

样例输入 1

5 4
bbobo
1 3
2 3
3 4
4 5
4 6
bobo
1 2
1 3
1 4
2 3
2 4
3 4
4 0
bobo

样例输出 1

2
4
0

说明

对于第一组测试数据,有 2 个四元组 $(1, 3, 4, 5), (2, 3, 4, 5)$。 对于第二组测试数据,有 4 个四元组 $(1, 2, 3, 4), (1, 4, 3, 2), (3, 2, 1, 4), (3, 4, 1, 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.