Going in Cycle!!
- Description
You are given a weighted directed graph with n vertices and m edges. Each cycle in the graph has a weight, which equals to sum of its edges. There are so many cycles in the graph with different weights. In this problem we want to find a cycle with the minimum mean.
- Input Format
The first line of input gives the number of cases, N. N test cases follow. Each one starts with two numbers n and m. m lines follow, each has three positive number a, b, c which means there is an edge from vertex a to b with weight of c.
- Output Format
For each test case output one line containing Case #x: followed by a number that is the lowest mean cycle in graph with 2 digits after decimal place, if there is a cycle. Otherwise print No cycle found.
- Sample Input
2
2 1
1 2 1
2 2
1 2 2
2 1 3
- Sample Output
Case #1: No cycle found.
Case #2: 2.50
- Hint
n ≤ 50
a, b ≤ n
c ≤ 10000000
- 题目大意
给定一个有n个顶点m条边的加权有向图,如果图中存在环(回路),环的平均值等于,环上边的权值之和除以构成环的边数,图中可能不止存在一个回路,计算平均权值最小的回路。
- 分析
这道题刚开始打的时候想法是从每个没被访问过点开始进行深搜,若搜到的点在本次搜索时已经被搜到过了,则认为发现一个环。每次搜索过的点都视为被访问过。但后来有神犇跟我说这样做不仅会超时还会少找到几个环(我也不知到为什么)。
正解:
这是一道最优比例环,属于01分数规划,即求一个环上某些信息的比值最优为多少。
显然答案满足单调性质,所以可以二分答案。对于一个二分出的Lim若有 Σi∈