I I U P C 2 0 0 6 | |
Problem G: Going in Cycle!! | |
Input: standard input Output: standard output | |
| |
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 | |
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 | |
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.”.
| |
Constraints | |
- n ≤ 50 - a, b ≤ n - c ≤ 10000000
| |
Sample Input | Output for Sample Input |
2 | Case #1: No cycle found. |
| |
Problemsetter: Mohammad Tavakoli Ghinani Alternate Solution: Cho
给定一个N个点M条边的有向加权图,求图中的平均权值最小的环
如果存在一个环,w1,w2,w3....wn
二分一个平均值
若平均值小于mid,则mid>(w1+w2+w3+...+wn)/n;
即 (w1-mid)+(w2-mid)+(w3-mid)+...+(wn-mid)<0
则转化成了求图中是否有负权回路
|
uva11090 - Going in Cycle!!
最新推荐文章于 2024-09-14 08:40:54 发布
该博客详细探讨了如何使用Bellman-Ford算法解决UVA11090问题,重点在于处理含有负权边的图中循环的检测。通过实例解析,阐述了算法的步骤和在图论中的应用,帮助读者理解负环检测的重要性。
摘要由CSDN通过智能技术生成