# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647603 | ToroTN | Travelling Merchant (APIO17_merchant) | C++14 | 80 ms | 3824 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>
using namespace std;
#define ll long long
ll n,m,num,b[105][1005],s[105][1005],u_i,v_i,w_i,d[105][105],profit[105][105],dis[105][105],type;
int main()
{
scanf("%lld%lld%lld",&n,&m,&num);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=num;j++)
{
scanf("%lld%lld",&b[i][j],&s[i][j]);
}
for(int j=1;j<=n;j++)d[i][j]=1e18;
}
for(int i=1;i<=n;i++)d[i][i]=0;
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&u_i,&v_i,&w_i);
d[u_i][v_i]=w_i;
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
{
if(b[i][k]!=-1&&s[j][k]!=-1)
{
profit[i][j]=max(profit[i][j],s[j][k]-b[i][k]);
}
}
}
}
ll st=0,md,ed=1e9;
while(ed>=st)
{
md=(st+ed)/2;
//printf("%lld %lld %lld\n",st,md,ed);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)dis[i][j]=1e9;
else dis[i][j]=d[i][j]*md-profit[i][j];
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
type=-1;
for(int i=1;i<=n;i++)
{
if(dis[i][i]<=0)
{
type=0;
}
}
if(type==0)
{
st=md+1;
}else
{
ed=md-1;
}
}
printf("%lld",ed);
}
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... |