Bzoj 1486 HNOI2009 min lap answer +dfs

Source: Internet
Author: User

Main topic: Bare Optimal proportional ring

Direct two-point answer +SPFA This will be t because the data card SPFA

SPFA when the negative ring is very small will degenerate into bellman-ford time complexity is O (nm) (like O (n*m^2)? I forgot).

In another way, enumerate each point starting at each point Dfs returns true only along the edge search that can reduce the point dis to the point in the stack.

Expected complexity O (n^2) The worst Complexity O (2^n) This thing can pass me too drunk

#include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include < algorithm> #define M 3030#define EPS 1e-9#define INF 1e7using namespace std;struct abcd{int to,next;double f;} Table[10100];int head[m],tot;int n,m,t;double a[10100],dis[m];void Add (int x,int y) {Table[++tot].to=y;table[tot]. Next=head[x];head[x]=tot;} void DFS (int x) {static int v[m];int i;if (v[x]==t) throw (true); V[x]=t;for (I=head[x];i;i=table[i].next) if (dis[x]+table [i].f<dis[table[i].to]) {Dis[table[i].to]=dis[x]+table[i].f;dfs (table[i].to);} v[x]=0;} BOOL Judge (double x) {int i;for (i=1;i<=m;i++) table[i].f=a[i]-x;for (i=1;i<=n;i++) {Try{++t;memset (dis,0,sizeof DIS);D fs (i);} catch (bool) {return true;}} return false;} Double bisection () {int i;double l=inf,r=-inf;for (i=1;i<=m;i++) l=min (L,a[i]), R=max (R,a[i]), while (R-l>eps) { Double mid= (l+r)/2;if (Judge (mid)) R=mid;else L=mid;} Return (L+R)/2;} int main () {int i,x,y;cin>>n>>m;for (i=1;i<=m;i++) scanf ("%d%d%lf", &x,&amP;y,&a[i]), ADD (x, y), cout<<fixed<<setprecision (8) <<bisection () <<endl;return 0;} 


Bzoj 1486 HNOI2009 min lap answer +dfs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.