Submission #919382

#TimeUsernameProblemLanguageResultExecution timeMemory
919382vnm06Travelling Merchant (APIO17_merchant)C++14
0 / 100
123 ms2136 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; long long inf=4e18; long long n, m, k; long long b[105][1005], s[105][1005]; long long vreme[105][105]; long long val[105][105]; long long ed[105][105]; long long distc[105][105]; bool pos(long long x) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(vreme[i][j]!=inf) ed[i][j]=x*vreme[i][j]-val[i][j]; else ed[i][j]=inf; distc[i][j]=ed[i][j]; } } for(int i=1; i<=n; i++) distc[i][i]=0; for(int k=1; k<=n; k++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(distc[i][k]==inf || distc[k][j]==inf) continue; if(distc[i][k]+distc[k][j]<distc[i][j]) distc[i][j]=distc[i][k]+distc[k][j]; } } } for(int k=1; k<=n; k++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(distc[i][k]==inf || distc[k][j]==inf) continue; if(distc[i][k]+distc[k][j]<distc[i][j]) return 1; } } } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i==j) continue; if(distc[i][j]+distc[j][i]<=0) return 1; } } return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m>>k; for(int i=1; i<=n; i++) { for(int j=1; j<=k; j++) { cin>>b[i][j]>>s[i][j]; if(b[i][j]==-1) b[i][j]=inf; } } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) vreme[i][j]=inf; vreme[i][i]=0; } for(int i=0; i<m; i++) { int u, v, d; cin>>u>>v>>d; vreme[u][v]=d; } for(int k=1; k<=n; k++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(vreme[i][k]+vreme[k][j]<vreme[i][j]) vreme[i][j]=vreme[i][k]+vreme[k][j]; } } } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { for(int t=1; t<=k; t++) if(val[i][j]<s[j][t]-b[i][t]) val[i][j]=s[j][t]-b[i][t]; } } long long le=0, ri=1e9+1; while(ri-le>1) { long long mid=(le+ri)/2; if(pos(mid)) le=mid; else ri=mid; } cout<<le<<endl; 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...