Submission #395318

#TimeUsernameProblemLanguageResultExecution timeMemory
395318Bill_00Travelling Merchant (APIO17_merchant)C++14
100 / 100
114 ms4404 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define N 105 #define K 1005 #define M 10005 typedef long long ll; using namespace std; ll n,m,k; ll u[M],v[M],w[M]; ll b[N][K],s[N][K]; ll dist[N][N],profit[N][N],adj[N][N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(ll i=1;i<=n;i++){ for(ll j=1;j<=k;j++){ cin >> b[i][j] >> s[i][j]; } for(ll j=1;j<=n;j++){ dist[i][j]=1000000001; } } for(ll i=1;i<=m;i++){ cin >> u[i] >> v[i] >> w[i]; dist[u[i]][v[i]]=w[i]; } for(ll q=1;q<=n;q++){ for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ dist[i][j]=min(dist[i][j],dist[i][q]+dist[q][j]); } } } for(ll q=1;q<=n;q++){ for(ll i=1;i<=n;i++){ if(dist[q][i]==1000000001) continue; for(ll j=1;j<=k;j++){ if(b[q][j]!=-1 && s[i][j]!=-1){ profit[q][i]=max(profit[q][i],s[i][j]-b[q][j]); } } } } ll l=0,r=1000000001; while(l!=r){ ll mid=(l+r+1)>>1; for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ adj[i][j]=profit[i][j]-mid*dist[i][j]; } } for(ll q=1;q<=n;q++){ for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ adj[i][j]=max(adj[i][j],adj[i][q]+adj[q][j]); } } } bool flag=0; for(ll i=1;i<=n;i++){ if(adj[i][i]>=0) flag=1; } if(flag==1){ l=mid; } else r=mid-1; } cout << l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...