Uvalive4080_warfare and Logistics

Source: Internet
Author: User

For an undirected graph, obtain two values, the shortest distance sum between all vertices and all other vertices, and delete the value after an edge.

The data size is 100 points and 1000 edges.

For example in the White Book, we will not mention finding the Shortest Path Tree for each vertex. If it is not the edge of the shortest path tree, we do not need to calculate the shortest path. because the number of points is only 100, the edge of the tree is only n-1. Therefore, for the tree with each vertex as the Source Vertex, you only need to re-calculate the n-1 shortest path. The complexity of each calculation is N * m, and the final complexity is N * n * m * log (). I personally think it is a little high, but it runs very fast.

Pay attention to the heavy edge. You need to make more judgments.

 

 

Summon code:

 

 

#include <iostream>#include <cstdio>#include <cstring>#include <queue>#define maxn 2222typedef long long ll;using namespace std;struct heapnode{    ll D,U;    bool operator < (heapnode ND) const {        return D>ND.D;    }};ll inf=~0U>>2;ll to[maxn],c[maxn],next[maxn],first[maxn],edge;ll u[maxn],v[maxn],w[maxn],minlen[maxn][maxn],tim[maxn][maxn];ll dis[maxn],from[maxn],C[maxn],f[maxn][maxn];bool key[maxn],akey[maxn],done[maxn];ll n,m,L,ans,sum;void _init(){    edge=-1,sum=ans=0;    for (int i=1; i<=n; i++)    {        first[i]=-1,C[i]=0;        for (int j=1; j<=n; j++) minlen[i][j]=inf;        for (int j=1; j<=m; j++) f[i][j]=0;    }}void addedge(int U,int V,int W){    edge++;    to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge;    edge++;    to[edge]=U,c[edge]=W,next[edge]=first[V],first[V]=edge;}ll dijkstra(int S,int EG,ll Dis[],ll From[],bool Key[]){    priority_queue

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.