제출 #983543

#제출 시각아이디문제언어결과실행 시간메모리
983543Abito여행하는 상인 (APIO17_merchant)C++17
0 / 100
53 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; struct edge{ int x,y,w; }; 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]; vector<edge> v; 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}); v.pb({x,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 t=1;t<=50;t++){ 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<int,int> x={eff[i][k].F+eff[k][j].S,eff[i][k].S+eff[k][j].S}; if (eff[i][j].F*x.S<eff[i][j].S*x.F) eff[i][j]=x; //cout<<eff[i][j].F<<' '<<eff[i][j].S<<endl; } } }} /*for (int i=1;i<=n;i++){ for (auto u:v){ if (eff[i][u.x]==-1) continue; pair<int,int> x={eff[i][u.x]} } }*/ /*for (int t=1;t<=50;t++){ for (int k=1;k<=n;k++){ for (int i=1;i<=n;i++){ if (eff[i][k].F==-1) continue; for (int j=1;j<=n;j++){ if (j==i || eff[k][j].F==-1 || eff[i][j].F==-1) continue; pair<int,int> x={eff[i][k].F+eff[k][j].S,eff[i][k].S+eff[k][j].S}; if (eff[i][j].F*x.S<eff[i][j].S*x.F) eff[i][j]=x; } } }}*/ int ans=0; 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]}; ans=max(ans,x.F/x.S); } }cout<<ans<<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...