Submission #972215

#TimeUsernameProblemLanguageResultExecution timeMemory
972215vjudge1Travelling Merchant (APIO17_merchant)C++14
0 / 100
54 ms3404 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N=110, K=1010, inf=1e18; int n, m, k; int b[N][K], s[N][K]; vector<pair<pair<int, int>, int>> e; int d[N][N]; int g[N][N]; int f[N][N]; bool check(int mid){ for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){ f[i][j]=inf; if (d[i][j]!=inf && d[i][j]<inf/mid) f[i][j]=mid*d[i][j]-g[i][j]; } for (int k=1; k<=n; ++k) for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){ f[i][j]=min(f[i][j], f[i][k]+f[k][j]); } return f[1][1]<=0; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); 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]; e.resize(m); for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) d[i][j]=inf; for (auto &i:e){ cin >> i.first.first >> i.first.second >> i.second; d[i.first.first][i.first.second]=min(d[i.first.first][i.first.second], i.second); } for (int k=1; k<=n; ++k) for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){ if (d[i][k]!=inf && d[k][j]!=inf) d[i][j]=min(d[i][j], d[i][k]+d[k][j]); } for (int i=1; i<=k; ++i){ for (int u=1; u<=n; ++u) for (int v=1; v<=n; ++v) if (b[u][k]!=-1 && s[v][k]!=-1 && b[u][k]<s[v][k]){ g[u][v]=max(g[u][v], s[v][k]-b[u][k]); } } int l=1, r=1e9; while (l<=r){ int mid=(l+r)>>1; if (check(mid)) l=mid+1; else r=mid-1; } cout << r << '\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...