la4080 Warfare and Logistics list + shortest

Source: Internet
Author: User

For illustration. Calculates the shortest random sub-ans1. and delete edges. Free to be able to get maximum and short-circuiting between the maximum points ans2 if these two do not communicate. As the shortest distance between two points L.

The first idea is to enumerate each edge and then run n the shortest time. However, this complexity is 1000*1000*100*log (100), too large: In fact, at a fixed starting point, the shortest time to find the unit. At the same time can find the shortest single source tree, only the deletion of the edge in the tree. The shortest path of the source point to any point will change, so in each run single source the most short-circuit, only need to enumerate the tree n-1 edge can be. Add up to delete each edge, in the case of the current source point. The sum of the shortest distance is added, and the last enumeration is able to find the one with the most added amount.

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue > #include <cstring> #include <vector>using namespace Std;typedef long Long ll;const ll inf= (1ll<<61    ); ll Cost[2020];int N,m;ll l;struct heapnode{ll D;    int u;    BOOL operator< (const heapnode& RHS) Const {return d>rhs.d;        } heapnode () {} heapnode (ll x,int y) {d=x;    U=y;    }};struct edge{int u,v;    ll W;    BOOL OK;        Edge () {} edge (int x,int y,ll z) {u=x;        V=y;        W=z;    Ok=true;    }};const int maxn=105;struct dij{int n,m;    Vector<edge> edges;    Vector<int> G[MAXN];    BOOL DONE[MAXN];    ll D[MAXN];    int P[MAXN];        void init (int n) {this->n=n;        for (int i=0; i<=n; i++) {g[i].clear ();    } edges.clear ();        } void Addedge (int x,int y,ll z) {edges.push_back (Edge (x, Y, z)); m=Edges.size ();    G[x].push_back (m-1);        } void Dijkstra (int s) {priority_queue

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

la4080 Warfare and Logistics list + shortest

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.