Bzoj 1486: [HNOI2009] Minimum Circle (two-point answer + DFS award negative circle)

Source: Internet
Author: User

The two-point answer M, and then the entire edge minus m, if there is a negative circle, then the mean smaller circle exists. Negative circles are judged by DFS.

---------------------------------------------------------------------------

#include <bits/stdc++.h>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define foreach (i, x) for (__typeof (X.begin ()) i = X.begin (); I! = X.end (); i++)using namespace std; const int MAXN = 3009;Const DOUBLE EPS = 1e-9;struct Edge {int to;Double Dist, W;};vector<edge> G[MAXN];int n;double D[MAXN];bool VIS[MAXN], F;void Dfs (int x) {vis[x] = true;foreach (E, g[x]) if (D[e->to] > D[x] + e->w) {if (!vis[e->to]) {D[e->to] = d[x] + e->w;DFS (e->to);} elseF = true;if (F) break;}Vis[x] = false;} bool Check (double m) {Rep (i, N) {foreach (it, g[i]) it->w = it->dist-m;Vis[i] = False, d[i] = 0;}F = false;Rep (i, N) {DFS (i);if (F) return true;}return false;}int main () {freopen ("test.in", "R", stdin);int m;cin >> n >> m;Rep (i, N) g[i].clear ();While (m--) {int u, v;double D;scanf ("%d%d%lf", &u, &v, &d); u--, v--;G[u].push_back (Edge) {V, D, 0});}double L = -1e7, R = 1e7;While (R-l > EPS) {Double m = (L + R)/2;check (m)? R = M:l = m;}printf ("%.8lf\n", L);return 0;}

---------------------------------------------------------------------------

1486: [HNOI2009] min loop time limit: Sec Memory Limit: MB
Submit: 1447 Solved: 679
[Submit] [Status] [Discuss] Descriptioninputoutputsample Inputsample Outputhint

Source

Bzoj 1486: [HNOI2009] Minimum Circle (two-point answer + DFS award negative circle)

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.