Link:
#include <stdio.h>int main(){ puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/46348771");}
Exercises
Score planning QWQ.
However, the kind of SPFA that it points into n times infers negative loops.
So there is a kind of black technology:
We started DFS from enumeration point I. And then sweep to the point J. Keep I~j the dots on this chain are marked, then force inference to sweep a point K. Whether it will go to this chain, and then is not able to update this point K and I distance ...
This thing is exponential-level time complexity. However, it is possible to cross the problem.
Code:
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 3010#define M 10100#define EPS 1e-8using namespace STD;DoubleMidstructeli{intV,n;Doublef,l;voidRe () {L=f-mid;}} E[M];inthead[n],cnt;inline voidAddintUintVDoubleL) {e[++cnt].v=v; E[cnt].f=l; E[cnt].n=head[u]; head[u]=cnt;}intN,m;BOOLVis[n];DoubleDist[n];BOOLDfsintx) {vis[x]=1;intI,v; for(I=HEAD[X];I;I=E[I].N) {v=e[i].v;if(DIST[V]>DIST[X]+E[I].L) {if(Vis[v]) {vis[x]=0;return 1; }Else{DIST[V]=DIST[X]+E[I].L;if(Dfs (v)) {vis[x]=0;return 1; }}}} vis[x]=0;return 0;}BOOLCheck () {memset(Dist,0,sizeofDIST); for(intI=1; i<=m;i++) e[i].re (); for(intI=1; i<=n;i++)if(Dfs (i))return 1;return 0;}intMain () {intI,a,b;DoubleCscanf("%d%d", &n,&m); for(i=1; i<=m;i++) {scanf("%D%D%LF", &a,&b,&c); Add (A,B,C); }Doublel=-1e7, r=1e7; for(i= -; i--;) {mid= (l+r)/2.0;if(check ()) R=mid;ElseL=mid; }printf("%.8lf\n", l);return 0;}
"BZOJ1486" "HNOI2009" minimum lap score planning DFS award negative ring.