[APIO 2017] Business Travel

Topic description:

qwq…

Topic Analysis:

First, preprocess the maximum profit that can be obtained between the two stalls, and record it as val[i][j].
While obtaining the maximum profit, it must be the shortest path and the optimal Freud processing the shortest between any two points.
then the problem becomes to find a maximum ratio cycle on the graph,
that is, to find m a x ( v a l c O s t ) 01 Score planning + SPFA to judge the positive loop

Topic link:

Luogu 3778

AC code:

// luogu-judger-enable-o2
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#define ll long long
const int maxm=1100;
ll val[maxm][maxm],b[maxm][maxm],s[maxm][maxm],dis[maxm][maxm],Dis[maxm];
int cur[maxm],vis[maxm];
int n,m,k;
std::queue <int> dl;
inline bool check(ll mid)
{
    while(!dl.empty()) dl.pop();
    for(int i=1;i<=n;i++) dl.push(i),vis[i]=0,cur[i]=0,Dis[i]=0;
    while(!dl.empty())
    {
        int now=dl.front();
        dl.pop();
        vis[now]=0;
        for(int i=1;i<=n;i++)
        if(Dis[i]<=Dis[now]+val[now][i]-dis[now][i]*mid)
        {
            Dis[i]=Dis[now]+val[now][i]-dis[now][i]*mid;
            if(!vis[i])
            {
                if((cur[i])==n) return 1;
                cur[i]++,vis[i]=1;
                dl.push(i);
            }
        }
    } 
    return 0;
}
int main()
{
    ll l=0,r=0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
     for(int j=1;j<=k;j++)
      scanf("%lld%lld",&b[i][j],&s[i][j]);
    for(int i=1;i<=n;i++)
     for(int j=1;j<=n;j++)
      for(int l=1;l<=k;l++)
       if(~b[i][l]&&~s[j][l])
        val[i][j]=std::max(val[i][j],s[j][l]-b[i][l]);
    memset(dis,127/3,sizeof(dis));
    for(int i=1;i<=m;i++)
    {
        int u,v;
        ll c;
        r=std::max(r,c);
        scanf("%d%d%lld",&u,&v,&c);
        dis[u][v]=c;
    }
    for(int k=1;k<=n;k++)
     for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
        dis[i][j]=std::min(dis[i][k]+dis[k][j],dis[i][j]);
    ll ans=0;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(check(mid)) l=mid+1,ans=mid;
        else r=mid-1;
    }
    printf("%lld\n",ans);
    return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326661084&siteId=291194637