Bzoj 1486 hnoi 2009 min Circle DFS

Source: Internet
Author: User

The main topic: give a direction graph, the path length of the graph to the smallest average ring.


Train of thought: two points this answer, and then all the edge of the right to subtract the value of the two, for all nodes Dfs, the process is only in the direction of decreasing length of search, if the search back to their own, indicating that can reduce the bounds, otherwise ascending the nether.

Do not use SPFA to award negative rings, because they will be t.


CODE:

#include <cmath> #include <cstdio> #include <iomanip> #include <cstring> #include <iostream > #include <algorithm> #define MAX 3010#define maxe 10010#define INF 1e10#define EPS 1e-12using namespace std; int points,edges;double Len; int Head[max],total;int Next[maxe],aim[maxe];d ouble length[maxe];    inline void Add (int x,int y,double len) {next[++total] = head[x];    Aim[total] = y;    Length[total] = len; HEAD[X] = total;} BOOL V[max];d ouble Mid,f[max];    void DFS (int x) {if (v[x]) throw true;    V[x] = true; for (int i = head[x]; i; i = Next[i]) if (F[x] + length[i]-mid < F[aim[i]]) {F[aim[i]] = f[x] + Leng            Th[i]-Mid;        DFS (Aim[i]); } V[x] = false;} Double L =-inf,r = INF;    int main () {cin >> points >> edges;        for (int x,y,i = 1; i <= edges; ++i) {scanf ("%d%d%lf", &x,&y,&len);        ADD (X,y,len);        L = min (L,len);    r = Max (R,len); } while (Fabs (r-l) > EPS) {mid = (L + r)/2.0;          BOOL flag = FALSE;                for (int i = 1; I <= points; ++i) {try {memset (f,0,sizeof (f));                memset (v,false,sizeof (v));            DFS (i);                }catch (bool) {flag = true;              Break        }} if (flag) R = Mid;    else L = mid;    } if (Fabs (L) < EPS) cout << "0.00000000" << Endl;    else cout << fixed << setprecision (8) << l << Endl; return 0;}


Bzoj 1486 hnoi 2009 min Circle 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.