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=101;
const ll inf=2e18;
ll n,m,k,buy[M][M],sell[M][M],dp[M][M][M],dis[M];
vector<pair<ll,ll>>adj[M];
vii v[M];
bool vis[M];
void bfs(ll x){
queue<ll>q;
q.push(x);
dis[x]=0;
for(int i=0;i<n;i++)
vis[i]=0;
vis[x]=1;
while(!q.empty()){
ll node=q.front();
q.pop();
for(auto it:v[node]){
if(!vis[it]){
vis[it]=1;
dis[it]=dis[node]+1;
q.push(it);
}
}
}
}
ll cont(ll x,ll y){
ll res=0;
for(int i=0;i<k;i++){
if(buy[x][i]>0)
res=max(res,sell[y][i]-buy[x][i]);
}
return res;
}
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--;
v[x].pb(y);
}
for(int i=0;i<n;i++){
bfs(i);
for(int j=0;j<n;j++){
if(j!=i&&dis[j]<=n)
adj[i].pb({j,dis[j]});
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
dp[i][j][0]=0;
else
dp[i][j][0]=-inf;
}
}
for(int time=0;time<n;time++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(auto it:adj[j]){
dp[i][it.F][time+it.S]=max(dp[i][it.F][time+it.S],dp[i][j][time]+cont(j,it.F));
}
}
}
}
ll ans=0;
for(int time=1;time<=n;time++){
for(int i=0;i<n;i++){
ans=max(ans,dp[i][i][time]/time);
}
}
cout<<ans<<'\n';
}
# | 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... |