Submission #907707

#TimeUsernameProblemLanguageResultExecution timeMemory
907707shezittTravelling Merchant (APIO17_merchant)C++14
33 / 100
86 ms2260 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define ii pair<int,int> const int N = 105; const int K = 1010; const int INF = LLONG_MAX / 2; int buy[N][K]; int sell[N][K]; int n, m, k; int dis[N][N]; int profit[N][N]; int ngraph[N][N]; void floyd_warshall(int adj[N][N]) { for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ for(int x=1; x<=n; ++x){ adj[j][x] = min(adj[j][x], adj[j][i] + adj[i][x]); } } } } signed main(){ cin >> n >> m >> k; for(int i=1; i<=n; ++i){ for(int j=1; j<=k; ++j){ cin >> buy[i][j] >> sell[i][j]; } } for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ dis[i][j] = INF; } } for(int i=1; i<=m; ++i){ int u, v, w; cin >> u >> v >> w; dis[u][v] = w; } floyd_warshall(dis); for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ for(int l=1; l<=k; ++l){ if(sell[j][l] != -1 && buy[i][l] != -1){ profit[i][j] = max(profit[i][j], sell[j][l] - buy[i][l]); } } } } int low = 1, high = 1e9; int ans = high; while(low <= high){ int mid = (low + high) / 2; for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ ngraph[i][j] = mid * min(INF / mid, dis[i][j]) - profit[i][j]; } } floyd_warshall(ngraph); bool ok = 0; for(int i=1; i<=n; ++i){ if(ngraph[i][i] <= 0){ ok = 1; } } if(ok){ low = mid+1; ans = mid; } else { high = mid-1; } } assert(ans > -1); 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...