JZOJ4716. The Flying Birds __ the puzzle

Source: Internet
Author: User

Original question: NOI2012 Food Festival topic purport

There are N-n-type birds, there are m-m holes, the first I-type birds have pi p_i only, through the J-J hole Need T (i,j) T (i,j) time. Each bird waits for a bird to pass through the same hole before it passes. Ask for the minimum total wait time.

Data Constraint
N≤40,m≤100,∑pi≤800,t (i,j) ≤1000 n\leq40,m\leq100,\sum p_i\leq800,t (i,j) \leq1000

For a Hole J J, the last passing bird I I to the answer of the contribution for T (I,J) T (I,J), the penultimate contribution for 2∗t (I,J) 2*t (i,j), the rest etc.
Consider the cost stream, which (Flow,cost) (Flow,cost) represents an edge in which the flow costs are cost: s S to each type of bird Company (pi,0) (p_i,0) each hole into a ∑pi \sum p_i point, each species of birds first these Point Edge (1,k∗t (I,J)) (1,k*t (i,j)) per hole to T-T Company (1,0) (1,0)

The number of sides is more, so use dynamic add edge. SRC

#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <

Algorithm> #include <queue> using namespace std;

#define N + #define M 100000 + typedef long LL;
BOOL Flag[n][10*n], vis[m];
int node[2*m], next[2*m], c[2*m], cost[2*m], head[m], tot = 1;

int d[10*m], dist[m], pre[m], rec[2*m], bel[2*m];
int tim[n][n], p[n];
int n, m, S, T, sump;

ll ans; void link (int u, int v, int w, int fee) {Node[++tot] = V, next[tot] = Head[u], C[tot] = W, cost[tot] = fee,
    Head[u] = tot;
Node[++tot] = u, Next[tot] = Head[v], C[tot] = 0, Cost[tot] =-fee, head[v] = tot;
    BOOL Spfa () {memset (Vis, 0, sizeof (VIS));
    memset (Dist, sizeof (Dist));
    int i = 0, j = 1;
    D[1] = S;
    Dist[s] = 0;
    Vis[s] = 1;
        while (I < j) {i + +;
        int now = D[i]; for (int p = Head[now]; p. p = next[p]) {if (! C[P]) continue;
            if (Dist[now] + cost[p] < Dist[node[p]]) {dist[node[p]] = Dist[now] + cost[p];
                PRE[NODE[P]] = p;
                    if (!vis[node[p]]) {vis[node[p]] = 1;
                    D[++J] = node[p];
                if (dist[d[i+1]] > Dist[d[j]) swap (d[i+1], d[j]);
    }} Vis[now] = 0; }

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.