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 F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
lli n,m,k;
void floyd(vector<vi> &al,vector<vi> &dis)
{
for(lli i=1;i<n+1;++i)
for(lli j=1;j<n+1;++j)
dis[i][j]=(10000000000000);
for(lli i=1;i<n+1;++i)
for(lli j=1;j<n+1;++j)
if(i!=j)
dis[i][j]=min(al[i][j],dis[i][j]);
for(lli i=1;i<=n;++i)
for(lli j=1;j<=n;++j)
for(lli k=1;k<=n;++k)
if(i!=k&&i!=j)
{
dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(;test>0;--test)
{
cin>>n>>m>>k;
vi p[n+1];
for(lli i=1;i<=n;++i)
{
for(lli j=0;j<2*k;++j)
{
lli f;
cin>>f;
p[i].pb(f);
}
}
vector<vi> al(n+1),dis(n+1),adj(n+1),bp(n+1),dis1(n+1);
for(lli i=0;i<n+1;++i)
for(lli j=0;j<n+1;++j)
{
al[i].pb(1000000000000000000);
adj[i].pb(1000000000000000000);
bp[i].pb(0);
dis1[i].pb(0);
dis[i].pb(0);
}
for(lli i=0;i<m;++i)
{
lli f,s,w;
cin>>f>>s>>w;
al[f][s]=w;
}
floyd(al,dis);
lli l=0,r=1000000000,ans=1;
for(lli i=1;i<=n;++i)
for(lli j=1;j<=n;++j)
for(lli l=0;l<k;++l)
if(p[i][2*l]!=-1&&p[j][2*l+1]!=-1)
bp[i][j]=max(bp[i][j],p[j][2*l+1]-p[i][2*l]);
for(lli i=1;i<=n;++i)
dis[i][i]=0;
while(l<=r)
{
lli m=(l+r)/2;
for(lli i=1;i<=n;++i)
for(lli j=1;j<=n;++j)
{
adj[i][j]=-(bp[i][j]-m*dis[i][j]);
}
floyd(adj,dis1);
lli x=1;
for(lli i=1;i<=n;++i)
{
x=min(dis1[i][i],x);
}
if(x<=0)
{
l=m+1;
ans=m;
}
else
{
r=m-1;
}
}
cout<<ans<<endl;
}
return(0);
}
Compilation message (stderr)
merchant.cpp: In function 'void floyd(std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&)':
merchant.cpp:23:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(lli i=1;i<n+1;++i)
^~~
merchant.cpp:27:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(lli i=1;i<=n;++i)
^~~
# | 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... |