inlinevoidbuild(double ans) { int i, x, y; for (x = 1; x <= n; ++ x) { for (i = head[x]; i; i = nex[i]) { y = ver[i]; val[i] = len[i] * ans - f[y]; } } return; }
inlinevoidspfa(int x) { tag[x] = 1; int i, y; for (i = head[x]; i; i = nex[i]) { y = ver[i]; if (dis[y] > dis[x] + val[i]) { if (tag[y]) return (void)(mark = 1); dis[y] = dis[x] + val[i]; spfa(y); } } return (void)(tag[x] = 0); }
inlineboolpd() { int i; for (i = 1; i <= n; ++ i) dis[i] = 0, tag[i] = 0; mark = 0; for (i = 1; i <= n; ++ i) { spfa(i); if (mark) returntrue; } returnfalse; }
signedmain() { int i, x, y, z; n = read(), m = read(); for (i = 1; i <= n; ++ i) f[i] = read(); for (i = 1; i <= m; ++ i) { x = read(), y = read(), z = read(); add_edge(x, y, z); }
double l = 0, r = 10000, mid;
while (r - l > 0.001) { mid = (l + r) / 2; build(mid); if (pd()) l = mid; else r = mid; }