HDU1839

来源:互联网 发布:帝国竞争算法程序 编辑:程序博客网 时间:2024/06/08 03:02

1.题目描述:

Delay Constrained Maximum Capacity Path

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1915    Accepted Submission(s): 641


Problem Description
Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with 1 corresponds to a mine from where some precious minerals are extracted. The vertex numbered with N corresponds to a minerals processing factory. Each edge has an associated travel time (in time units) and capacity (in units of minerals). It has been decided that the minerals which are extracted from the mine will be delivered to the factory using a single path. This path should have the highest capacity possible, in order to be able to transport simultaneously as many units of minerals as possible. The capacity of a path is equal to the smallest capacity of any of its edges. However, the minerals are very sensitive and, once extracted from the mine, they will start decomposing after T time units, unless they reach the factory within this time interval. Therefore, the total travel time of the chosen path (the sum of the travel times of its edges) should be less or equal to T.
 

Input
The first line of input contains an integer number X, representing the number of test cases to follow. The first line of each test case contains 3 integer numbers, separated by blanks: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and T (1 <= T <= 500.000). Each of the next M lines will contain four integer numbers each, separated by blanks: A, B, C and D, meaning that there is an edge between vertices A and B, having capacity C (1 <= C <= 2.000.000.000) and the travel time D (1 <= D <= 50.000). A and B are different integers between 1 and N. There will exist at most one edge between any two vertices.
 

Output
For each of the X test cases, in the order given in the input, print one line containing the highest capacity of a path from the mine to the factory, considering the travel time constraint. There will always exist at least one path between the mine and the factory obbeying the travel time constraint.
 

Sample Input
22 1 101 2 13 104 4 201 2 1000 152 4 999 61 3 100 153 4 99 4
 

Sample Output
1399
 

Author
Mugurel Ionut Andreica
 

Source
Politehnica University of Bucharest Local Team Contest 2007
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  4114 1841 4063 3873 1546 
 
2.题意概述:

有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。一条路径的运输容量取决与这条路径中的运输容量最小的那条边。

3.解题思路:

因为每条路径的容量取决于这条路径中所有边中的最小容量,所以我们可以以此枚举最小容量。但是如果一个一个容量的枚举,那明显效率太低了。通过分析,可以看出,如果最低容量越大,那么符合要求的路径就越少,所以,根据容量的大小,路径数量是单调的。有了单调性,就可以利用二分法了。只要把容量从大到小进行排序,然后二分之,很快便能算出答案。

4.AC代码:

#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 10010#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;struct node{int to, val, time;node(int a, int b, int c) { to = a; val = b; time = c; }};vector<node> mp[maxn];vector<int> edge;int dis[maxn];bool vis[maxn];void spfa(int min_len, int n){memset(vis, 0, sizeof(vis));fill(dis, dis + n + 1, INF);deque<int> q;vis[1] = 1;dis[1] = 0;q.push_back(1);while (!q.empty()){int u = q.front();q.pop_front();vis[u] = 0;int sz = mp[u].size();for (int i = 0; i < sz; i++){int v = mp[u][i].to;int w = mp[u][i].val;int t = mp[u][i].time;if (dis[v] > dis[u] + t && w >= min_len){dis[v] = dis[u] + t;if (!vis[v]){vis[v] = 1;if (!q.empty() && dis[v] <= dis[q.front()])q.push_front(v);elseq.push_back(v);}}}}}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();#endifint t, n, m, T;scanf("%d", &t);while (t--){scanf("%d%d%d", &n, &m, &T);for (int i = 1; i <= n; i++)mp[i].clear();edge.clear();while (m--){int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);mp[a].push_back(node(b, c, d));mp[b].push_back(node(a, c, d));edge.push_back(c);}sort(edge.begin(), edge.end());int l = 0, r = edge.size() - 1, mid, ans = 0;while (l <= r){mid = l + (r - l) / 2;spfa(edge[mid], n);if (dis[n] <= T){ans = edge[mid];l = mid + 1;}elser = mid - 1;}printf("%d\n", ans);}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);#endifreturn 0;}

0 0
原创粉丝点击