#P3199. [HNOI2009] 最小圈

    ID: 4036 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>2009各省省选湖南深度优先搜索 DFS分数规划

[HNOI2009] 最小圈

Problem Description

Consider a weighted directed graph G=(V,E)G=(V,E) and w:E→Rw: E \rightarrow \mathbb{R}. Each edge e=(i,j)e=(i,j) (i≠ji \neq j, i,j∈Vi, j \in V) has weight wi,jw_{i,j}. Let n=∣V∣n = |V|.

A sequence c=(c1,c2,⋯ ,ck)c=(c_1, c_2, \cdots, c_k) (ci∈Vc_i \in V) is a cycle in GG if and only if (ci,ci+1)(c_i, c_{i+1}) (1≤i<k1 \le i < k) and (ck,c1)(c_k, c_1) are both in EE. We call kk the length of cycle cc, and set ck+1=c1c_{k+1} = c_1. The average value of cycle c=(c1,c2,⋯ ,ck)c=(c_1, c_2, \cdots, c_k) is defined as

$$\mu(c)= \frac 1 k \sum\limits_{i=1}^{k} w_{c_i,c_{i+1}}.$$

Let μ′(G)=min⁡cμ(c)\mu'(G)=\min_c \mu(c) be the minimum average value over all cycles cc in GG.

Given G=(V,E)G=(V,E) and w:E→Rw: E \rightarrow \mathbb{R}, compute the minimum average value μ′(G)\mu'(G) over all cycles cc in GG.

Input Format

The first line contains two positive integers nn and mm, separated by a space. Here n=∣V∣n = |V| and m=∣E∣m = |E| denote the number of vertices and edges, respectively.

The next mm lines each contain three numbers i,j,wi,ji, j, w_{i,j}, indicating there is an edge (i,j)(i, j) with weight wi,jw_{i,j}. Note that edge weights can be real numbers. The input guarantees that the graph G=(V,E)G=(V,E) is connected, contains at least one cycle, and there exists a vertex that can reach all other vertices.

Output Format

Output a real number μ′(G)\mu'(G), printed with 88 digits after the decimal point.

4 5
1 2 5
2 3 5
3 1 5
2 4 3
4 1 3
3.66666667
2 2
1 2 -2.9
2 1 -3.1
-3.00000000

Hint

  • Constraints: For 100%100\% of the testdata, 2≤n≤30002 \le n \le 3000, 1≤m≤100001 \le m \le 10000, ∣wi,j∣≤107|w_{i,j}| \le 10^7, 1≤i,j≤n1 \le i, j \le n and i≠ji \neq j.
  • Note: There exists an O(nm)O(nm) solution; an O(nmlog⁡n)O(nm \log n) solution also passes.

Translated by ChatGPT 5