90pts暴力搜索+剪枝,求证复杂度,为什么能拿90分?(我一开始以为是30)
TLE on #9 是我的复杂度错误,还是写错了?
谢大佬!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int NR = 1010;
int n, m;
struct edge
{
int nxt, to;
int c, f;
}e[NR * 2];
int head[NR], cnt;
void add(int x, int y, int c, int f)
{
e[++cnt] = (edge){head[x], y, c, f};
head[x] = cnt;
}
int cn[NR], fn[NR];
int vis[NR];
long long ans = 0;
void dfs(int x, long long c, long long f)
{
if (c != 0 && ans > (long long)floor(1.0 * f / c * 1e6)) return;
vis[x] = 1;
if (x == n)
{
ans = max(ans, (long long)floor(1.0 * f / c * 1e6));
vis[x] = 0;
return;
}
for (int i = head[x]; i; i = e[i].nxt)
{
int y = e[i].to;
if (!vis[y])
{
dfs(y, c + e[i].c, min(f, 1ll * e[i].f));
}
}
vis[x] = 0;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i ++)
{
int a, b, c, f;
scanf("%d%d%d%d", &a, &b, &c, &f);
add(a, b, c, f);
add(b, a, c, f);
}
dfs(1, 0, 1e9);
printf("%lld\n", ans);
return 0;
}