Submission #104741

#TimeUsernameProblemLanguageResultExecution timeMemory
104741puyu_liaoTravelling Merchant (APIO17_merchant)C++14
54 / 100
195 ms2340 KiB
#include<bits/stdc++.h> #include<stdint.h> using namespace std; #define IOS {cin.tie(0);ios_base::sync_with_stdio(false);} #define int int64_t #define N 105 #define K 1005 const int INF = 1e14; const double eps = 1e-6; int n; int bb[N][K],ss[N][K]; int w[N][N],dis[N][N]; double dp[N][N]; bool chk(double mm){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { dp[i][j] = mm*dis[i][j] - w[i][j]; } for(int x=1;x<=n;x++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { dp[i][j] = min(dp[i][j],dp[i][x] + dp[x][j]); } for(int i=1;i<=n;i++) if(dp[i][i] < 0) return true; return false; } int32_t main() { IOS; int m,k,a,b,t; cin >> n >> m >> k; for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) cin >> bb[i][j] >> ss[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<=n;i++) dis[i][i] = 0; for(int i=0;i<m;i++){ cin >> a >> b >> t; dis[a][b] = t; } for(int x=1;x<=n;x++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j] = min(dis[i][j],dis[i][x] + dis[x][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(j != i && dis[i][j] != INF) { for(int x=1;x<=k;x++) if(ss[j][x] >= 0 && bb[i][x] >= 0) w[i][j] = max(w[i][j],ss[j][x] - bb[i][x]); } else w[i][j] = 0; } double l=eps,r = INF; for(int cnt=0;cnt<120;cnt++){ double mm = (l+r)*0.5; if(chk(mm)) l = mm; else r = mm; } int ll = (floor(l)); while(chk(ll+1-eps)) ll++; cout << ll << '\n'; 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...