Submission #497143

#TimeUsernameProblemLanguageResultExecution timeMemory
497143mp007mp여행하는 상인 (APIO17_merchant)C++14
100 / 100
100 ms4236 KiB
#include<bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<x<<"\n";
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pii;
int mod = 1e9+7;
ll inf = 1e9+5;
ll linf = 1ll*inf*inf;
const int maxn = 105;
ll sel[maxn][maxn*10],buy[maxn][maxn*10],dist[maxn][maxn],bnf[maxn][maxn];
int n,m,k;
inline bool check(ll x){
    ll d[maxn][maxn];
    for(int i=0;i<maxn;i++){
        for(int j=0;j<maxn;j++){
            d[i][j] = linf;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(dist[i][j] == linf)continue;
            d[i][j] = dist[i][j]*x-bnf[i][j];
        }
    }
    for(int z=1;z<=n;z++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                d[i][j] = min(d[i][j],d[i][z]+d[z][j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i][i] <= 0){
            return true;
        }
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout<<"Hello, World!";
    //return 0;
    int l=0,r=inf;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            cin>>buy[i][j]>>sel[i][j];
        }
    }
    for(int i=0;i<maxn;i++){
        for(int j=0;j<maxn;j++){
            dist[i][j] = linf;
        }
    }
    for(int i=0;i<m;i++){
        ll u,v,w;
        cin>>u>>v>>w;
        dist[u][v] = min(dist[u][v],w);
    }
    for(int z=1;z<=n;z++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dist[i][j] = min(dist[i][j],dist[i][z]+dist[z][j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int z=1;z<=k;z++){
                if(buy[i][z] != -1 && sel[j][z] != -1){
                    bnf[i][j] = max(bnf[i][j],sel[j][z]-buy[i][z]);
                }
            }
        }
    }
    while(r-l>1){
        int mid = (l+r)>>1;
        if(check(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout<<l;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...