# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241391 | nafis_shifat | Travelling Merchant (APIO17_merchant) | C++14 | 141 ms | 2296 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn=101;
const ll inf=1e10+6;
const ll inf2=1e13;
const int mxk=1001;
int n;
ll b[mxn][mxk],s[mxn][mxk];
ll g[mxn][mxn];
ll pr[mxn][mxn];
ll adj[mxn][mxn];
bool check(ll d) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
adj[i][j]=d*g[i][j]-max(0ll,pr[i][j]);
adj[i][j]=min(adj[i][j],inf2);
}
adj[i][i]=inf;
}
for(int k=1;k<=n;k++) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
}
}
}
for(int i=1;i<=n;i++)
if(adj[i][i]<=0) {
return true;
}
return false;
}
int main() {
int m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++) {
for(int j=1;j<=k;j++) {
scanf("%lld",&b[i][j]);
scanf("%lld",&s[i][j]);
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
g[i][j]=inf;
for(int i=1;i<=m;i++) {
int u,v;ll w;
scanf("%d%d%lld",&u,&v,&w);
g[u][v]=w;
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
pr[i][j]=-inf;
for(int x=1;x<=k;x++) {
if(s[j][x]!=-1 && b[i][x]!=-1)
pr[i][j]=max(pr[i][j],s[j][x]-b[i][x]);
}
}
}
for(int l=1;l<=n;l++) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
g[i][j]=min(g[i][j],g[i][l]+g[l][j]);
}
}
}
int lo=1;
int hi=1e9+2;
int ans=0;
while(lo<=hi) {
int mid=lo+hi>>1;
if(check(mid)) {
ans=mid;
lo=mid+1;
} else {
hi=mid-1;
}
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |