比赛 |
2025暑期集训第5场图论专场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Milk Pumping |
最终得分 |
100 |
用户昵称 |
pcx |
运行时间 |
0.177 s |
代码语言 |
C++ |
内存使用 |
3.82 MiB |
提交时间 |
2025-07-09 10:15:48 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1e4,INF=0x3f3f3f3f;
typedef long long LL;
typedef pair<int,int> PII;
int n,m,dis[N],vis[N];
int nex[N],h[N],to[N],c[N],f[N],idx;
void add1(int x,int y,int c1,int f1){
to[idx++]=y;
c[idx]=c1;
f[idx]=f1;
nex[idx]=h[x];
h[x]=idx;
return;
}
void add(int x, int y, int c1, int f1) {
to[idx] = y;
c[idx] = c1;
f[idx] = f1;
nex[idx] = h[x];
h[x] = idx++;
}
int dijkstra(int mf){
memset(dis,0x3f,sizeof(dis));dis[1]=0;
memset(vis,0,sizeof(vis));
priority_queue<PII,vector<PII>,greater<PII> > pq;
pq.push(make_pair(0,1));
while(!pq.empty()){
int u=pq.top().second;
pq.pop();
if(vis[u])continue;
vis[u]=1;
for(int i=h[u];~i;i=nex[i]){
int v=to[i];
if(dis[v]>dis[u]+c[i]&&f[i]>=mf){
dis[v]=dis[u]+c[i];
pq.push(make_pair(dis[v],v));
}
}
}
return dis[n];
}
int main() {
freopen("pump.in","r",stdin);
freopen("pump.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
memset(h,-1,sizeof(h));
cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b,c1,f1;
cin>>a>>b>>c1>>f1;
add(a,b,c1,f1);
add(b,a,c1,f1);
}
double maxa=0;
for(int mf=1;mf<=1000;mf++){
int tc=dijkstra(mf);
if(tc!=INF){
double ans=(double)mf/tc;
if(ans>maxa){
maxa=ans;
}
}
}
cout<<(int)(maxa*1000000)<<endl;
return 0;
}