QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#8846. 反转道路 II

统计

JAG 王国是一个奇特的王国,其 $N$ 个城市仅通过单向道路连接。$N$ 个城市编号为 $1$ 到 $N$。ICPC(国际特征产品公司)每天将产品从位于城市 $S$ 的工厂运输到位于城市 $T$ 的仓库。为了提高效率,ICPC 同时使用多辆卡车。每辆卡车从 $S$ 出发,通过单向道路网络到达 $T$,途经若干城市(或直接到达)。为了降低交通拥堵和事故风险,没有任何两辆卡车会走同一条道路。

现在,ICPC 希望在上述约束条件下,尽可能多地使用卡车来提高日常运输效率。JAG 王国受 ICPC 的财政影响巨大,考虑改变单向道路的方向,以增加 ICPC 日常运输的卡车数量。由于改变过多道路的方向会造成混乱,JAG 王国决定最多只改变一条道路的方向。

如果不存在可以通过改变某条道路方向来提高运输效率的情况,则 JAG 王国无需改变任何道路。请检查改变一条道路的方向是否能提高当前的最大卡车数量。如果可以,请计算在允许改变一条单向道路方向的情况下,卡车所能走的不相交道路集合的最大数量,以及为了实现该最大值,可以选择改变方向的道路数量。

输入格式

输入包含多个数据集。数据集的数量不超过 $100$。

每个数据集的第一行包含四个整数:城市数量 $N$ ($2 \le N \le 1,000$),道路数量 $M$ ($1 \le M \le 10,000$),工厂所在城市 $S$ 和仓库所在城市 $T$ ($1 \le S, T \le N, S \neq T$)。

接下来的 $M$ 行描述了道路信息。第 $i$ 行包含两个整数 $a_i$ 和 $b_i$ ($1 \le a_i, b_i \le N, a_i \neq b_i$),表示第 $i$ 条道路是从 $a_i$ 指向 $b_i$ 的。

输入结束由一行包含四个零的行表示。

输出格式

对于每个数据集,输出一行,包含两个由空格分隔的整数:如果改变一条道路的方向可以提高当前日常运输的最大卡车数量,则第一个输出整数为改变道路后的新最大值,第二个输出整数为为了实现该新最大值,可以选择改变方向的道路数量。否则,即如果通过改变任何一条道路的方向都无法增加当前最大值,则第一个输出整数为当前的最大值,第二个输出整数为 $0$。

样例

样例输入 1

4 4 1 4
1 2
3 1
4 2
3 4
7 8 1 7
1 2
1 3
2 4
3 4
4 5
4 6
5 7
7 6
6 4 5 2
1 2
1 3
4 5
5 6
10 21 9 10
9 1
9 2
9 3
9 4
10 1
10 2
10 3
10 4
1 5
2 5
2 6
3 6
3 7
4 7
4 8
1 8
5 10
6 10
7 10
10 8
10 9
2 15 1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
0 0 0 0

样例输出 1

1 2
2 1
0 0
4 6
15 0

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.