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
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn = 105, inf = 1e9;
int n, m, k, a[maxn][maxn], vl[maxn][maxn], b[maxn][maxn*10], s[maxn][maxn*10];
long long d[maxn][maxn];
void Enter()
{
cin>>n>>m>>k;
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
a[i][j]=inf;
for (int i=1;i<=n;++i)
for (int j=1;j<=k;++j)
cin>>b[i][j]>>s[i][j];
while(m--)
{
int u, v, w;
cin>>u>>v>>w;
a[u][v]=min(a[u][v],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)
vl[i][j]=max(vl[i][j],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]=-inf;
if(a[i][j]==inf)
continue;
d[i][j]=vl[i][j]-1ll*mid*a[i][j];
}
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(1ll*inf,max(d[i][j],d[i][t]+d[t][j]));
for(int i=1;i<=n;++i)
if(d[i][i]>=0)
return true;
return false;
}
void Solve()
{
int l=1, h=1e9, mid;
while(l<=h)
{
mid=(l+h)/2;
if (Check(mid))
l=mid+1;
else
h=mid-1;
}
cout<<h;
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
Enter();
Prepare();
Solve();
}
# | 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... |