# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312770 | Kuuhaku | Travelling Merchant (APIO17_merchant) | C++17 | 76 ms | 1468 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], maxx=1e10;
void Enter()
{
cin>>n>>m>>k;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
a[i][j]=1e10;
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(int mid)
{
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
{
d[i][j] = -1e10;
if (a[i][j] == 1e10)
continue;
d[i][j] = vl[i][j] - 1ll*mid * a[i][j];
}
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
d[i][j] = max(d[i][j], d[i][k] + d[k][j]);
for (int i=1;i<=n;++i)
if(d[i][i]>= 0)
return true;
return false;
}
void Solve()
{
long long l=1, r=1e10, 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... |