https://open.kattis.com/problems/mravi
Function f is the solution of the problem.
Don't worry if you don't know C# because it's quite similar to C++, Java
FILENAME | FILESIZE | SHA-1 SUM | |
---|---|---|---|
mravi.cs | 1424 bytes | 3cd94e9e7b40579adea564c42b242396479ad98d | download |
Edit and resubmit this submission.
mravi.cs
using System;
public static class MathD
{
public static double Max(double a, double b)
{
if (a > b) return a;
return b;
}
}
class Program{
const int N=1001;
int n, u, v, x, t;
bool[,] a= new bool[N,N];
double[] b = new double[N];
int[] c= new int[N], k= new int[N];
double f(int u){
if (k[u] != -1) return c[u] == 0 ? k[u] / b[u] : Math.Sqrt(k[u]) / b[u];
double res = 0;
for(int v=1; v<=n; v++){
if (a[u,v]==true){
res= MathD.Max(res, c[u]==0 ? f(v)/b[u] : Math.Sqrt(f(v))/b[u]);
}
}
return res;
}
Program(){
n= Int32.Parse(Console.ReadLine());
for(int i=1; i<n; i++){
string[] s= Console.ReadLine().Split(" ");
u= int.Parse(s[0]);
v= int.Parse(s[1]);
x= int.Parse(s[2]);
t= int.Parse(s[3]);
a[u,v]= true;
b[v]= (double)x/100;
c[v]= t;
}
string[] st= Console.ReadLine().Split(" ");
for(int i=1; i<=n; i++)
k[i]= Convert.ToInt32(st[i-1]);
b[1]= 1;
c[1]= 0;
Console.Write(f(1));
}
static void Main(string[] args){
new Program();
}
}
No comments:
Post a Comment