QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#15056. 强连通图

الإحصائيات

故事背景

JYY 最近痴迷于图的强连通性,所以对于任何有向图,JYY 都希望增加一些边使得这个图变成强连通图。

题目描述

JYY现在得到了一个 $N$ 个点 $M$ 条边的有向图,所有点从 $1$ 到 $n$ 编号。

JYY 想知道:

  1. 在给定的图中,最多能选出多少个点,使得这些点在原图中两两可达?
  2. 在给定的图中,最少增加多少条边,可以使得这个图变成强连通图?

其中,一个有向图 $G(V,E)$是强连通的,当且仅当任意顶点 $a,b\in V$($a \ne b$)之间都存在 $a\to b$ 和 $b\to a$ 的路径。由于加边操作是很麻烦的,JYY 保证,在最优方案中,只需要至多增加 1000 条边就可以把原图变成强连通图。

输入格式

第一行包含两个整数 $N$ 和 $M$。

接下来 $M$ 行,每行两个整数 $x$ 和 $y$,表示图中有一条从 $x$ 到 $y$ 的有向边。

输出格式

输出文件的第一行包含一个整数 $C$,表示 JYY 第一个问题的答案。

输出文件的第一行包含二个整数 $K$,表示 JYY 第二个问题的答案。

接下来 $K$ 行,每行两个整数表示一条有向边,描述第二个问题的一个最佳加边方案。如有多种满足条件的方案,输出任意一个。

评分方式

对于每一个测试点,如果仅第一行正确,则可以得到 2 分;

如果第一行和第二行均正确但是方案不正确,则可以得到 4 分;

如果输出全不正确,则可以得到 10 分;

其余情况得 0 分。

样例数据

样例 1 输入

4 4
1 3
1 4
2 3
2 4

样例 1 输出

1
2
3 1
4 2

样例 2 输入

10 12
3 7
1 2
4 5
7 10
10 8
6 8
2 1
3 8
10 3
6 8
7 3
4 1

样例 2 输出

3
4
8 4
5 9
1 10
9 6

样例解释

两个样例输出都可以得到 10 分。

数据规模

对于 $10\%$ 的数据满足 $N = 6$;

对于 $30\%$ 的数据满足 $N \leq 100$, $M \leq 2\,000$;

对于 $80\%$ 的数据满足 $N \leq 1\,000$, $M \leq 20\,000$;

对于 $100\%$ 的数据满足 $1 \leq N \leq 10^4$, $0 \leq M \leq 2 \cdot 10^5$,最优方案中需要加入的边数不超过 1000。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.