数据弱小
查看原帖
数据弱小
1395172
Nlu5E5Bl楼主2025/1/4 16:23

这题数据及其弱小,优化的dfs就能过

#include <bits/stdc++.h>
using namespace std;

const int N=1000;
struct E{
	int u,v,c,f;
};
vector<E> e[N];
bool vis[N];
int ans=0;

void dfs(int st,int ed,int c,int f){
	if(st==ed){
		ans=max((int)(1e6*(double)f/(double)c),ans);
		return;
	}
	if(c!=0 and (int)(1e6*(double)f/(double)c)<ans){
		return;
	}
	for(E i:e[st]){
		int v=i.v;
		if(vis[v]==1){
			continue;
		}
		vis[v]=1;
		dfs(v,ed,i.c+c,min(f,i.f));
		vis[v]=0;
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v,c,f;
		scanf("%d%d%d%d",&u,&v,&c,&f);
		e[u].push_back((E){u,v,c,f});
		e[v].push_back((E){v,u,c,f});
	}
	dfs(1,n,0,0x7fffffff);
	cout<<ans<<endl;
}

这是一道最短路题,这不是正解,好孩子不要学我,发出来仅供娱乐,也求求审核别卡我

2025/1/4 16:23
加载中...