知识点:枚举,最短路
这个题的正解应该是枚举+最短路,枚举每个边的流量,然后求起点到终点的最短路,当然小于枚举的流量的边其实就是不连通的,这样这个题就做出来了,但是一开始我写的是深搜,加了剪枝,用邻接矩阵存储,勉强过了,但是这个枚举+最短路确跑的快很多,明明复杂度也有1e7了,可能是因为实际中有很多断边的原因把,深搜的代码就不放了
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
struct node {
int x, d;
node() {}
node(int a, int b): x(a), d(b) {}
bool operator < (const node &a) const {
return d > a.d;
}
};
int tot, ver[N], c[N], f[N], nxt[N], head[N];
int n, m, a[N];
void add(int x, int y, int t1, int t2) {
ver[++tot] = y;
c[tot] = t1; f[tot] = t2;
nxt[tot] = head[x]; head[x] = tot;
}
int bfs(int x) {
priority_queue<node> q;
q.push(node(1, 0));
int vis[N] = {};
while (!q.empty()) {
node now = q.top(); q.pop();
if (now.x == n) return now.d;
if (vis[now.x]) continue;
vis[now.x] = 1;
for (int i = head[now.x]; i; i = nxt[i]) {
if (f[i] >= x) q.push(node(ver[i], now.d + c[i]));
}
}
return -1;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, z;
scanf("%d%d%d%d", &x, &y, &z, &a[i]);
add(x, y, z, a[i]);
add(y, x, z, a[i]);
}
double ans = 0;
for (int i = 1; i <= m; i++) {
int tmp = bfs(a[i]);
if (tmp == -1) continue;
ans = max(ans, 1.0 * a[i] / tmp);
}
cout << (int) (ans * 1e6);
return 0;
}