QOJ.ac

QOJ

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

#16221. 最小圈

الإحصائيات

考虑带权的有向图 $G=(V,E)$ 以及 $w:E\to R$,每条边 $e=(i,j)(i\ne j,i\in V,j\in V)$ 的权值定义为 $w_{i,j}$,令 $n=|V|$。$c=(c_1,c_2,\cdots,c_k)(c_i\in V)$ 是 $G$ 中的一个圈当且仅当 $(c_i,c_{i+1})(1\le i < k)$ 和 $(c_k,c_1)$ 都在 $E$ 中,这时称 $k$ 为圈 $c$ 的长度同时令 $c_{k+1}=c_1$,并定义圈 $c=(c_1,c_2,\cdots,c_k)$ 的平均值为

$$\mu(c)=\sum_{i=1}^{k} w_{c_i,c_{i+1}}/k,$$

即 $c$ 上所有边的权值的平均值。令 $\mu^*(c)=Min{\mu(c)}$ 为 $G$ 中所有圈 $c$ 的平均值的最小值。现在的目标是:在给定了一个图 $G=(V,E)$ 以及 $w:E\to R$ 之后,请求出 $G$ 中所有圈 $c$ 的平均值的最小值 $\mu^*(c)=\min\{\mu(c)\}$。

输入格式

第一行包含两个整数 $n$ 和 $m$,并用一个空格隔开,其中 $n=|V|,m=|E|$ 分别表示图中有 $n$ 个点和 $m$ 条边。接下来 $m$ 行,每行包含用空格隔开的 3 个数 $i,j$ 和 $w_{i,j}$,表示有一条边 $(i,j)$ 且该边的权值为 $w_{i,j}$。输入数据保证图 $G=(V,E)$ 连通,存在圈且有一个点能到达其他所有点。

输出格式

输出仅包含一个实数 $\mu^*(c)=\min\{\mu(c)\}$,要求输出到小数点后 8 位。

样例数据

样例数据 1

input.txt

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

output.txt

3.66666667

样例数据 2

input.txt

2 2
1 2 -2.9
2 1 -3.1

output.txt

-3.00000000

输入输出样例说明

样例 1 中共有 2 个圈 $(1,2,3)$ 和 $(1,2,4)$。其中第一个圈的平均值为 5,第二个圈的平均值为 $11/3$。样例 2 中存在一个负圈。

数据规模

  • 20% 的数据:$n\le 100,m\le 1000$;
  • 50% 的数据:$n\le 1000,m\le 5000$;
  • 100% 的数据:$n\le 3000,m\le 10000$;
  • 100% 的数据:$|w_{i,j}|\le 10^7$。

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.