Submission #983552

#TimeUsernameProblemLanguageResultExecution timeMemory
983552AbitoTravelling Merchant (APIO17_merchant)C++17
0 / 100
19 ms2136 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=105,KK=1005; int n,m,K,dis[N][N],b[N][KK],s[N][KK]; bool vis[N]; pair<int,int> eff[N][N]; vector<pair<int,int>> adj[N]; void dijkstra(int s){ for (int i=1;i<=n;i++) vis[i]=0,dis[s][i]=-1; dis[s][s]=0; priority_queue<pair<int,int>> pq; pq.push({0,s}); while (!pq.empty()){ int x=pq.top().S; pq.pop(); if (vis[x]) continue; vis[x]=1; for (auto u:adj[x]){ if (dis[s][u.F]==-1 || dis[s][u.F]>dis[s][x]+u.S){ dis[s][u.F]=dis[s][x]+u.S; pq.push({-dis[s][u.F],u.F}); } } }return; } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>m>>K; for (int i=1;i<=n;i++) for (int j=1;j<=K;j++) cin>>b[i][j]>>s[i][j]; for (int i=1;i<=m;i++){ int x,y,w; cin>>x>>y>>w; adj[x].pb({y,w}); } for (int i=1;i<=n;i++) dijkstra(i); for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ if (dis[i][j]==-1) eff[i][j]={-1,-1}; else{ int mx=0; for (int k=1;k<=K;k++){ if (b[i][k]==-1 || s[j][k]==-1) continue; mx=max(mx,s[j][k]-b[i][k]); } eff[i][j]={mx,dis[i][j]}; } //cout<<eff[i][j].F<<' '<<eff[i][j].S<<" "; }//cout<<endl; } for (int i=1;i<=n;i++){ for (int j=i;j<=n;j++){ if (i==j || eff[i][j].F==-1) continue; for (int k=1;k<=n;k++){ if (eff[i][k].F==-1 || eff[k][j].F==-1) continue; pair<__int128,__int128> x={eff[i][k].F+eff[k][j].S,eff[i][k].S+eff[k][j].S}; if ((__int128)eff[i][j].F*x.S<(__int128)eff[i][j].S*x.F) eff[i][j]=x; //cout<<eff[i][j].F<<' '<<eff[i][j].S<<endl; } } } pair<int,int> ans={0,1}; for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ if (i==j || eff[i][j].F==-1) continue; pair<int,int> x={eff[i][j].F,eff[i][j].S+dis[j][i]}; if (ans.F*x.S<ans.S*x.F) ans=x; } }cout<<ans.F/ans.S<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...