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>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
int b[103][1003];
int s[103][1003];
li dist[103][103]; //shortest time
li profit[103][103]; //koliko profitira od u do v (na pocetku uzima strogo shortest path)
int main()
{
FAST;
int n,m,k; cin>>n>>m>>k;
fff(i,1,n) fff(j,1,k) cin>>b[i][j]>>s[i][j];
fff(i,1,n) fff(j,1,n) dist[i][j]=mod;
while (m--)
{
int u,v,w; cin>>u>>v>>w;
dist[u][v]=w;
}
fff(pivot,1,n)
{
ff(i,1,pivot) ff(j,1,pivot) dist[i][j]=min(dist[i][j],dist[i][pivot]+dist[pivot][j]);
ff(i,1,pivot) ff(j,1,pivot) dist[i][pivot]=min(dist[i][pivot],dist[i][j]+dist[j][pivot]);
ff(i,1,pivot) ff(j,1,pivot) dist[pivot][j]=min(dist[pivot][j],dist[pivot][i]+dist[i][j]);
//za svaki slucaj ponavljamo
ff(i,1,pivot) ff(j,1,pivot) dist[i][j]=min(dist[i][j],dist[i][pivot]+dist[pivot][j]);
ff(i,1,pivot) ff(j,1,pivot) dist[i][pivot]=min(dist[i][pivot],dist[i][j]+dist[j][pivot]);
ff(i,1,pivot) ff(j,1,pivot) dist[pivot][j]=min(dist[pivot][j],dist[pivot][i]+dist[i][j]);
}
fff(i,1,n) dist[i][i]=0;
fff(i,1,n) fff(j,1,n) if (dist[i][j]>mod-4) dist[i][j]=0; //samo ne...
fff(predmet,1,k)
fff(i,1,n) fff(j,1,n)
if (s[j][predmet]>-1 && b[i][predmet]>-1)
profit[i][j]=max(profit[i][j],(li)(s[j][predmet]-b[i][predmet]));
/*fff(i,1,n)
{
fff(j,1,n) cout<<dist[i][j]<<" ";
cout<<endl;
} cout<<endl;
fff(i,1,n) fff(j,1,n)
{
cout<<"immediate profit: ("<<i<<","<<j<<") = "<<profit[i][j]<<endl;
}*/
#define Try(i,j,k) if (dist[i][j]>0 && dist[j][k]>0 && (dist[i][k]==0 || (ld)(profit[i][j]+profit[j][k])/(dist[i][j]+dist[j][k]) > (ld)(profit[i][k])/dist[i][k])) profit[i][k]=profit[i][j]+profit[j][k],dist[i][k]=dist[i][j]+dist[j][k];
fff(pivot,1,n)
{
ff(i,1,pivot) ff(j,1,pivot) Try(i,pivot,j);
ff(i,1,pivot) ff(j,1,pivot) Try(pivot,i,j);
ff(i,1,pivot) ff(j,1,pivot) Try(i,j,pivot);
}
li ans=0;
fff(i,1,n) if (dist[i][i]>0)
{
ans=max(ans,profit[i][i]/dist[i][i]);
}
cout<<ans<<"\n";
}
//Note to self: Check for overflow
# | 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... |