ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1016 [USACO 2012 Dec S]Milk Routing 最短路 忽略部分路径 三个参量

2022-08-19 04:01:24  阅读:153  来源: 互联网

标签:10 dist idx int USACO 15 Routing ver 1016


 链接:https://ac.nowcoder.com/acm/contest/26077/1016
来源:牛客网

题目描述

Farmer John's farm has an outdated network of M pipes (1 <= M <= 500) for pumping milk from the barn to his milk storage tank. He wants to remove and update most of these over the next year, but he wants to leave exactly one path worth of pipes intact, so that he can still pump milk from the barn to the storage tank.  The pipe network is described by N junction points (1 <= N <= 500), each of which can serve as the endpoint of a set of pipes. Junction point 1 is the barn, and junction point N is the storage tank. Each of the M bi-directional pipes runs between a pair of junction points, and has an associated latency (the amount of time it takes milk to reach one end of the pipe from the other) and capacity (the amount of milk per unit time that can be pumped through the pipe in steady state). Multiple pipes can connect between the same pair of junction points.  For a path of pipes connecting from the barn to the tank, the latency of the path is the sum of the latencies of the pipes along the path, and the capacity of the path is the minimum of the capacities of the pipes along the path (since this is the "bottleneck" constraining the overall rate at which milk can be pumped through the path). If FJ wants to send a total of X units of milk through a path of pipes with latency L and capacity C, the time this takes is therefore L + X/C.  Given the structure of FJ's pipe network, please help him select a single path from the barn to the storage tank that will allow him to pump X units of milk in a minimum amount of total time.

输入描述:

* Line 1: Three space-separated integers: N M X (1 <= X <= 1,000,000).

* Lines 2..1+M: Each line describes a pipe using 4 integers: I J L C.
I and J (1 <= I,J <= N) are the junction points at both ends
of the pipe. L and C (1 <= L,C <= 1,000,000) give the latency
and capacity of the pipe.

输出描述:

* Line 1: The minimum amount of time it will take FJ to send milk
along a single path, rounded down to the nearest integer.
示例1

输入

复制
3 3 15
1 2 10 3
3 2 10 2
1 3 14 1

输出

复制
27

说明

INPUT DETAILS:
FJ wants to send 15 units of milk through his pipe network. Pipe #1
connects junction point 1 (the barn) to junction point 2, and has a latency
of 10 and a capacity of 3. Pipes #2 and #3 are similarly defined.

OUTPUT DETAILS:
The path 1->3 takes 14 + 15/1 = 29 units of time. The path 1->2->3 takes
20 + 15/2 = 27.5 units of time, and is therefore optimal.

分析

题意:将牛奶从1号点送到n号点,要求 L + x / c 最小。C是经过的道路的最小容量。L是经过的道路的延时总和。

有三个参量:L,X,C。每个参量变化都会导致答案变化,所以一开始没搞清楚怎么做

但毕竟边数很少,可以直接枚举每一种C。然后计算从1号点到达n号点的最小延时。就得到了L + x / C

计算最短路的时候,忽略容量小于C的路径。

 

//-------------------------代码----------------------------

#define int ll
const int N = 1e5+10;
int n,m,x;
int e[N],ne[N],w1[N],w2[N],idx,h[N];

void add(int a,int b,int c,int d) {
    e[idx] = b,ne[idx] = h[a],w1[idx] = c,w2[idx] = d,h[a] = idx ++ ;
} 
int dist[1000];
bool vis[1000];

void dij(int u) {
    priority_queue<pii,V<pii>,greater<pii> > q;
    q.push({0,1});
    ms(dist,0x3f);ms(vis,0);
    dist[1] = 0;
    while(q.size()) {
        auto tmp = q.top();q.pop();
        int ver = tmp.second;
        if(vis[ver]) continue;
        vis[ver] = 1;
        fe(i,ver) {
            if(w2[i] < u) continue;
            if(dist[e[i]] > dist[ver] + w1[i]) {
                dist[e[i]] = dist[ver] + w1[i];
                q.push({dist[e[i]],e[i]});
            }
        }
    }
}

void solve()
{
    cin>>n>>m>>x;
    V<int> q;
    ms(h,-1);
    fo(k,1,m) {
        int i,j,l,c;
        cin>>i>>j>>l>>c;
        add(i,j,l,c);add(j,i,l,c);
        q.pb(c);
    }
    ll ans = INF;
    for(auto it:q) {
        dij(it);
        ans = min(ans,1ll * (dist[n] + x / it));
    }
    cout<<ans<<endl;
}
void main_init() {}
signed main(){
    AC();clapping();TLE;
    cout<<fixed<<setprecision(12);
    main_init();
//  while(cin>>n,n)
//  while(cin>>n>>m,n,m)
//    int t;cin>>t;while(t -- )
    solve();
//    {solve(); }
    return 0;
}

/*样例区


*/

//------------------------------------------------------------

 

标签:10,dist,idx,int,USACO,15,Routing,ver,1016
来源: https://www.cnblogs.com/er007/p/16600695.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有