题目链接:
题目
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others)
Memory Limit: 65535/65535 K (Java/Others)
问题描述
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.
输入
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.
输出
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.
样例
input
2
2 1 10
1 2 13 10
4 4 20
1 2 1000 15
2 4 999 6
1 3 100 15
3 4 99 4
output
13
99
题意
找一条1到N的路线,使得时间花费<=T的前提下容量最小的边的容量值最大。
题解
最小值最大,想到二分答案。
每次二分出容量后,跑残图的最短路,判断可行性。
代码
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 1e4 + 10;
const int maxm = 10 * maxn;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
struct Edge {
int u, v, c, w;
Edge(int u, int v, int c, int w) :u(u), v(v), c(c), w(w) {}
};
int n, m, T;
vector<int> G[maxn];
vector<Edge> egs;
void addEdge(int u, int v, int c, int w) {
egs.push_back(Edge(u, v, c, w));
G[u].push_back(egs.size() - 1);
}
int mid;
int inq[maxn];
LL d[maxn];
bool spfa() {
memset(inq, 0, sizeof(inq));
for (int i = 0; i <= n; i++) d[i] = INF;
queue<int> Q;
d[0] = 0, inq[0] = 1, Q.push(0);
while (!Q.empty()) {
int u = Q.front(); Q.pop();
inq[u] = 0;
for (int i = 0; i < G[u].size(); i++) {
Edge& e = egs[G[u][i]];
if (e.c < mid) continue;
if (d[e.v]>d[u] + e.w) {
d[e.v] = d[u] + e.w;
if (!inq[e.v]) inq[e.v] = 1, Q.push(e.v);
}
}
}
if (d[n - 1] <= T) return true;
return false;
}
void init() {
for (int i = 0; i <= n; i++) G[i].clear();
egs.clear();
}
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
scanf("%d%d%d", &n, &m, &T);
init();
int ma= -1;
while (m--) {
int u, v, c,w;
scanf("%d%d%d%d", &u, &v, &c, &w), u--, v--;
ma = max(ma, c);
addEdge(u, v, c,w);
addEdge(v, u, c,w);
}
int l = 1, r = ma+1;
while (l + 1 < r) {
mid = l + (r - l) / 2;
if (spfa()) l = mid;
else r = mid;
}
printf("%d
", l);
}
return 0;
}