【UVA11090】Going in Cycle!!

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值