• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 7,comments - 3,trackbacks - 0

            Base Station

            Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65768/32768 K (Java/Others)
            Total Submission(s): 844    Accepted Submission(s): 353


            Problem Description
            A famous mobile communication company is planning to build a new set of base stations. According to the previous investigation, n places are chosen as the possible new locations to build those new stations. However, the condition of each position varies much, so the costs to built a station at different places are different. The cost to build a new station at the ith place is Pi (1<=i<=n).

            When complete building, two places which both have stations can communicate with each other.

            Besides, according to the marketing department, the company has received m requirements. The ith requirement is represented by three integers Ai, Bi and Ci, which means if place Aand Bi can communicate with each other, the company will get Ci profit.

            Now, the company wants to maximize the profits, so maybe just part of the possible locations will be chosen to build new stations. The boss wants to know the maximum profits.
             

            Input
            Multiple test cases (no more than 20), for each test case:
            The first line has two integers n (0<n<=5000) and m (0<m<=50000).
            The second line has n integers, P1 through Pn, describes the cost of each location.
            Next m line, each line contains three integers, Ai, Bi and Ci, describes the ith requirement.
             

            Output
            One integer each case, the maximum profit of the company.
             

            Sample Input
            5 5 1 2 3 4 5 1 2 3 2 3 4 1 3 3 1 4 2 4 5 3
             

            Sample Output
            4
             

            Author
            liulibo
             

            Source
             

            Recommend
            lcy
             
            論文題,Amber最小割模型里面的,最大權閉合圖,因為數組開的太大了,吃了一次RE......
            最大權閉合圖不用說了,邊看成收益點,連向S,流量是點權,站點看成花費點,連向T,流量也是點權,其他按照原圖連邊,流量是無限大,之后做一次最小割,割值就是你未選的收益點+選定花費點(因為是閉合圖,所以割肯定是簡單割,想一下割的定義,就明白割值的含義了),用你總收益-割值,就是答案。
            用SAP求的最小割,漸漸愛上SAP了,Dinic不用了.....
            代碼:

            #include <cstdio>
            #include 
            <cstring>
            #include 
            <iostream>
            #include 
            <queue>
            using namespace std;

            const int maxnode = 60000;
            const int maxedge = 320000;
            const long long inf = (1LL << 35);

            int S, T, cnt;
            int head[maxnode], gap[maxnode], pre[maxnode], cur[maxnode], dis[maxnode];

            struct Edge
            {
                
            int s, t;
                
            int next;
                
            long long w;
            } st[maxedge];

            void init()
            {
                memset(head, 
            -1sizeof(head));
                cnt 
            = 0;
            }

            void AddEdge(int s, int t, long long w)
            {
                st[cnt].s 
            = s;
                st[cnt].t 
            = t;
                st[cnt].w 
            = w;
                st[cnt].next 
            = head[s];
                head[s] 
            = cnt;
                cnt
            ++;

                st[cnt].s 
            = t;
                st[cnt].t 
            = s;
                st[cnt].w 
            = 0;
                st[cnt].next 
            = head[t];
                head[t] 
            = cnt;
                cnt
            ++;
            }

            void bfs()
            {
                memset(gap, 
            0sizeof(gap));
                memset(dis, 
            -1sizeof(dis));
                queue 
            <int> Q;
                Q.push(T);
                dis[T] 
            = 0;
                gap[
            0= 1;
                
            int k, t;
                
            while (!Q.empty())
                {
                    k 
            = Q.front();
                    Q.pop();
                    
            for (int i = head[k]; i != -1; i =st[i].next)
                    {
                        t 
            = st[i].t;
                        
            if (dis[t] == -1 && st[i ^ 1].w > 0)
                        {
                            dis[t] 
            = dis[k] + 1;
                            gap[dis[t]]
            ++;
                            Q.push(t);
                        }
                    }
                }
            }

            long long sap()
            {
                
            int i;
                
            for (i = S; i <= T; ++i)
                    cur[i] 
            = head[i];
                pre[S] 
            = S;
                
            int u = S, v;
                
            long long flow = 0;
                
            long long aug = inf;
                
            bool flag;
                
            while (dis[S] <= T)
                {
                    flag 
            = false;
                    
            for (i = cur[u]; i != -1; i = st[i].next)
                    {
                        v 
            = st[i].t;
                        
            if (st[i].w > 0 && dis[u] == dis[v] + 1)
                        {
                            cur[u] 
            = i;
                            flag 
            = true;
                            pre[v] 
            = u;
                            aug 
            = (aug > st[i].w) ? st[i].w : aug;
                            u 
            = v;
                            
            if (v == T)
                            {
                                flow 
            += aug;
                                
            for (u = pre[u]; v != S; u = pre[u])
                                {
                                    v 
            = u;
                                    st[cur[u]].w 
            -= aug;
                                    st[cur[u] 
            ^ 1].w += aug;
                                }
                                aug 
            = inf;
                            }
                            
            break;
                        }
                    }
                    
            if (flag == truecontinue;
                    
            int mint = T;
                    
            for (i = head[u]; i != -1; i = st[i].next)
                    {
                        v 
            = st[i].t;
                        
            if (st[i].w > 0 && mint > dis[v])
                        {
                            cur[u] 
            = i;
                            mint 
            = dis[v];
                        }
                    }
                    gap[dis[u]]
            --;
                    
            if (gap[dis[u]] == 0break;
                    gap[dis[u] 
            = mint + 1]++;
                    u 
            = pre[u];
                    
            if (u == S) aug = inf;
                }
                
            return flow;
            }

            int main()
            {
                
            int n, m;
                
            while (scanf("%d%d"&n, &m) != EOF)
                {
                    init();
                    S 
            = 0;
                    T 
            = n + m + 1;
                    
            int sum = 0;
                    
            for (int i = 1; i <= n; ++i)
                    {
                        
            int x;
                        scanf(
            "%d"&x);
                        AddEdge(m 
            + i, T, x);
                    }
                    
            for (int i = 1; i <= m; ++i)
                    {
                        
            int a, b, c;
                        scanf(
            "%d%d%d"&a, &b, &c);
                        AddEdge(S, i, c);
                        AddEdge(i, m 
            + a, inf);
                        AddEdge(i, m 
            + b, inf);
                        sum 
            += c;
                    }
                    bfs();
                    sum 
            -= sap();
                    printf(
            "%d\n", sum);
                }
                
            return 0;
            }
            posted on 2011-10-15 22:10 LLawliet 閱讀(126) 評論(0)  編輯 收藏 引用 所屬分類: 網絡流
            久久综合九色综合精品| 久久香综合精品久久伊人| 婷婷五月深深久久精品| 2019久久久高清456| 婷婷久久综合九色综合九七| 久久免费观看视频| 久久婷婷人人澡人人| 色播久久人人爽人人爽人人片aV| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 伊人久久大香线蕉综合Av| 东方aⅴ免费观看久久av| 狠狠干狠狠久久| 中文字幕无码久久精品青草| 久久精品无码专区免费青青| 久久精品无码一区二区三区日韩| 久久久无码精品亚洲日韩京东传媒| 久久久久亚洲AV无码永不| 久久亚洲色一区二区三区| 久久夜色精品国产噜噜亚洲AV| 国产精品成人99久久久久| 狠狠色丁香久久婷婷综合| 国产免费福利体检区久久| 欧美一区二区三区久久综合| 蜜臀久久99精品久久久久久 | 久久天天躁狠狠躁夜夜2020一 | 久久精品国产99久久久古代| 国产成人无码精品久久久免费| 久久精品青青草原伊人| 久久综合色区| 国产精品久久久久一区二区三区 | 亚洲精品无码久久久久去q| 九九久久精品无码专区| 久久精品99久久香蕉国产色戒 | 久久国产V一级毛多内射| 成人久久精品一区二区三区| 久久亚洲精品无码aⅴ大香| 久久久久久久综合综合狠狠| 久久精品国产只有精品66| 久久久久久久尹人综合网亚洲 | 久久人人爽人人爽人人片AV麻豆| 亚洲精品高清久久|