| 比赛 | 
    10101115 | 
    评测结果 | 
    AEWWEEEEEE | 
    | 题目名称 | 
    最小密度路径 | 
    最终得分 | 
    10 | 
    | 用户昵称 | 
    Citron酱 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-15 09:55:22 | 
显示代码纯文本
#include <iostream>
#include <fstream>
#define I_F "path.in"
#define O_F "path.out"
#define MAX 51
using namespace std;
long map[MAX][MAX];
bool f[MAX][MAX]={{false}};
short n,m;
double ans;
ifstream fin(I_F);
void Input();
void Dfs(short x, short y, short l, long s);
void Search();
int main()
{
	Input();
	Search();
	return 0;
}
void Input()
{
	fin>>n>>m;
	short i,x,y;
	for (i=0; i<m; i++)
	{
		fin>>x>>y;
		fin>>map[x][y];
		f[x][y]=true;
	}
}
void Dfs(short x, short y, short l, long s)
{
	if (x!=y)
	{
		for (short i=1; i<=n; i++)
			if (f[x][i])
				Dfs(i,y,l+1,s+map[x][i]);
	}
	else
		if ((double)s/l<ans)
			ans=(double)s/l;
}
void Search()
{
	long q,i;
	short x,y;
	fin>>q;
	ofstream fout(O_F);
	fout.setf(ios::fixed);
	fout.precision(3);
	for (i=0; i<q; i++)
	{
		fin>>x>>y;
		ans=2000000000;
		Dfs(x,y,0,0);
		if (ans<2000000000)
			fout<<ans<<'\n';
		else
			fout<<"OMG!\n";
	}
	fout.close();
	fin.close();
}