# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312756 | Kuuhaku | Travelling Merchant (APIO17_merchant) | C++17 | 186 ms | 3248 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.
//Oct14
#define tasknames "merchant"
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 105;
int n, m, k, b[maxn][maxn*10], s[maxn][maxn*10];
long long a[maxn][maxn], d[maxn][maxn], vl[maxn][maxn];
void Enter()
{
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)a[i][j]=3e18;
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)
cin>>b[i][j]>>s[i][j];
for(int i=1;i<=m;i++)
{
int u, v, w;
cin>>u>>v>>w;
a[u][v]=min(a[u][v],1ll*w);
}
}
void Prepare()
{
for(int t=1;t<=n;t++)
for(int i=1; i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=min(a[i][j],a[i][t]+a[t][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int t=1;t<=k;t++)
{
if(b[i][t]==-1||s[j][t]==-1)continue;
vl[i][j]=max(vl[i][j],1ll*s[j][t]-b[i][t]);
}
}
bool Check(long long mid)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
d[i][j]=3e18;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(a[i][j]==3e18)continue;
d[i][j]=min(d[i][j],a[i][j]*mid-vl[i][j]);
}
for(int i=1;i<=n;i++)
d[i][i]=3e18;
for(int t=1;t<=n;t++)
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
d[i][j]=min(d[i][j],d[i][t]+d[t][j]);
if(d[i][j]>3e18)
d[i][j]=3e18;
}
if(d[i][i]<=0)return true;
}
return false;
}
void Solve()
{
long long l=0, r=1e15, mid;
while(l<=r)
{
mid=(l+r)/2;
if(Check(mid))
l=mid+1;
else r=mid-1;
}
cout<<r;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(fopen(tasknames".INP","r"))
{
freopen(tasknames".INP","r",stdin);
freopen(tasknames".OUT","w",stdout);
}
Enter();
Prepare();
Solve();
}
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... |