QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100 Difficulty: [show] Hackable ✓

#2214. Link Cut Digraph

الإحصائيات

在阅读了论文《Incremental Topological Ordering and Strong Component Maintenance》之后,你打算出一道这样的题。

给定一个包含 $n$ 个顶点的图。初始时图中没有边。共有 $m$ 次操作。每次操作首先向图中添加一条给定的有向边,然后输出满足 $u$ 可达 $v$ 且 $v$ 可达 $u$ 的数对 $(u, v)$ ($1 \le u < v \le n$) 的数量。

你能在 ICPC 比赛中实现论文中描述的算法吗?

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 10^5$, $1 \le m \le 2.5 \cdot 10^5$)。

接下来的 $m$ 行,每行包含两个整数 $u$ 和 $v$ ($1 \le u, v \le n$),表示一条新添加的有向边。允许存在平行边和自环。

输出格式

输出 $m$ 个整数,每行一个,表示添加每条给定边之后满足条件的数对数量。

样例

输入 1

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

输出 1

0
0
1
1
2
6

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#624Editorial Open集训队作业 解题报告 by 涂竣博Qingyu2026-01-02 23:17:37 Download
#581Editorial Open集训队作业 解题报告 by 龚咏乔Qingyu2026-01-02 22:33:51 Download

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.