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;
typedef long long ll;
typedef vector<ll> vii;
#define pb push_back
#define S second
#define F first
const ll M=1001;
const ll inf=2e18;
ll n,m,k,buy[M][M],sell[M][M],res[M],dis[M];
vector<pair<ll,ll>>adj[M],radj[M];
bool vis[M];
void dij(){
for(int i=1;i<n;i++)
dis[i]=inf,res[i]=inf;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>q;
q.push({0,0});
while(!q.empty()){
pair<ll,ll> p=q.top();
q.pop();
vis[p.S]=1;
dis[p.S]=p.F;
for(auto it:adj[p.S]){
if(!vis[it.F])
q.push({it.S+p.F,it.F});
}
}
q.push({0,0});
for(int i=0;i<n;i++)
vis[i]=0;
while(!q.empty()){
pair<ll,ll> p=q.top();
q.pop();
vis[p.S]=1;
res[p.S]=p.F;
for(auto it:radj[p.S]){
if(!vis[it.F])
q.push({it.S+p.F,it.F});
}
}
for(int i=0;i<n;i++)
res[i]+=dis[i];
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>m>>k;
for(int i=0;i<n;i++){
for(int j=0;j<k;j++)
cin>>buy[i][j]>>sell[i][j];
}
for(int i=0;i<m;i++){
ll x,y,z;
cin>>x>>y>>z;
x--,y--;
adj[x].pb({y,z});
radj[y].pb({x,z});
}
dij();
ll ans=0;
for(int i=1;i<n;i++){
for(int j=0;j<k;j++){
if(sell[i][j]>=0&&buy[0][j]>=0)
ans=max(ans,(sell[i][j]-buy[0][j])/res[i]);
}
}
cout<<ans;
}
# | 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... |