QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#18400. 不道德的图 (Hard)

Statistiques

本题与“不道德的图 (Easy)”除 $N$ 和 $M$ 的限制外完全相同。

在图的世界里,两个从未交流过的顶点也可能拥有同一个孩子。

对于一个无环简单有向图,若三个不同的顶点 $x, y, z$ 满足以下所有条件,则称其为不道德关系:

  • 存在从 $x$ 到 $z$ 的边,且存在从 $y$ 到 $z$ 的边。
  • 不存在连接 $x$ 和 $y$ 的边。

在图的世界里,这种关系被视为一种相当有趣的结构。

给定一个包含 $N$ 个顶点和 $M$ 条边的无环简单有向图。请计算该图中不道德关系的个数。

输入格式

第一行包含两个由空格分隔的整数 $N$ 和 $M$。$(3\leq N\leq 50\,000;$ $1\leq M\leq 50\,000)$

接下来的 $M$ 行,每行包含两个由空格分隔的整数 $u, v$,表示一条从顶点 $u$ 指向顶点 $v$ 的有向边。$(1\leq u,v\leq N)$

给定的图是一个无环简单有向图。

输入的所有数字均为整数。

输出格式

输出给定图中存在的不道德关系的个数。

样例

样例输入 1

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

样例输出 1

3

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.