Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- n = int(raw_input().strip())
- adj = {i: [] for i in xrange(n)}
- for i in xrange(n-1):
- a, b, x, t = map(int, raw_input().strip().split())
- a -= 1
- b -= 1
- x /= 100.0
- t = bool(t)
- adj[a].append((b, x, t))
- adj[b].append((a, x, t))
- req = map(int, raw_input().strip().split())
- order = [0]
- pipe = [None] * n
- pipe[0] = 0, 1, False
- for i in xrange(n):
- v = order[i]
- for a, x, t in adj[v]:
- if pipe[a] is not None:
- continue
- order.append(a)
- pipe[a] = v, x, t
- for i in xrange(n-1, 0, -1):
- v = order[i]
- p, x, t = pipe[v]
- r = req[v]
- if t:
- r = min(r, r**.5)
- req[p] = max(req[p], r/x)
- print '{:.4f}'.format(req[0])
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment