标签:print etc bzoj line 就会 put its out reg
第一行包含二个整数N,M
一个浮点数,保留二位小数。表示答案,数据保证答案大于0
1<=N<=5000
1 #include <bits/stdc++.h> 2 #define il inline 3 #define RG register 4 #define ll long long 5 #define eps (1e-4) 6 #define inf (1e9) 7 #define N (5010) 8 9 using namespace std; 10 11 struct edge{ int nt,to,dis; }g[10010]; 12 13 int head[N],vis[N],n,m,num; 14 double dis[N]; 15 16 il int gi(){ 17 RG int x=0,q=1; RG char ch=getchar(); 18 while ((ch<‘0‘ || ch>‘9‘) && ch!=‘-‘) ch=getchar(); 19 if (ch==‘-‘) q=-1,ch=getchar(); 20 while (ch>=‘0‘ && ch<=‘9‘) x=x*10+ch-48,ch=getchar(); 21 return q*x; 22 } 23 24 il void insert(RG int from,RG int to,RG int dis){ 25 g[++num]=(edge){head[from],to,dis},head[from]=num; return; 26 } 27 28 il int spfa(RG int x,RG double key){ 29 vis[x]=1; RG int v; 30 for (RG int i=head[x];i;i=g[i].nt){ 31 v=g[i].to; 32 if (dis[v]>dis[x]+g[i].dis+key){ 33 dis[v]=dis[x]+g[i].dis+key; 34 if (vis[v] || spfa(v,key)) return 1; 35 } 36 } 37 vis[x]=0; return 0; 38 } 39 40 il int check(RG double key){ 41 for (RG int i=1;i<=n;++i) vis[i]=dis[i]=0; 42 for (RG int i=1;i<=n;++i) if (spfa(i,key)) return 1; return 0; 43 } 44 45 int main(){ 46 #ifndef ONLINE_JUDGE 47 freopen("coconut.in","r",stdin); 48 freopen("coconut.out","w",stdout); 49 #endif 50 n=gi(),m=gi(),n+=2; 51 for (RG int i=1,u,v,a,b,c,d;i<=m;++i){ 52 u=gi(),v=gi(),a=gi(),b=gi(),c=gi(),d=gi(); 53 insert(u,v,b+d); if (c) insert(v,u,a-d); 54 } 55 RG double l=0,r=inf,mid,ans=0; 56 while (r-l>eps) mid=(l+r)/2,check(mid)?(ans=mid,l=mid):r=mid; 57 printf("%0.2lf\n",ans); return 0; 58 }
标签:print etc bzoj line 就会 put its out reg
原文地址:http://www.cnblogs.com/wfj2048/p/7668044.html