链接: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示例1
along a single path, rounded down to the nearest integer.
输入
复制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 From: https://www.cnblogs.com/er007/p/16600695.html