This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 1001;
ll d[nmax][nmax];
ll g[nmax][nmax];
void floyd(int n){
for(int k = 1; k <= n; k++){
for(int j = 1; j <= n; j++){
for(int i= 1; i <= n; ++i){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int m; cin >> m;
int k; cin >> k;
ll b[n + 1][k + 1], s[n + 1][k + 1];
for(int i= 1; i <= n; i++){
for(int j= 1; j <= k; j++){
cin >> b[i][j] >> s[i][j];
}
}
ll opt[n + 1][n + 1];
for(int i= 1; i <= n; i++){
for(int j = 1; j <= n; j++){
opt[i][j] = -1e18;
d[i][j] = 1e18;
if(j == i) continue;
opt[i][j] = 0;
for(int x = 1; x <= k; x++){
if(s[j][x] == -1 || b[i][x] == -1) continue;
opt[i][j] = max(opt[i][j], s[j][x] - b[i][x]);
}
}
}
for(int i = 1; i <= m; i++){
int u, v, t; cin >> u >> v >> t;
d[u][v] = t;
}
floyd(n);
for(int i= 1; i <= n; i++){
for(int j = 1; j <= n; j++)
g[i][j] = d[i][j];
}
ll l = 0, r = 1e9;
int last = 0;
while(l + 1 < r){
ll mid = (l+ r) / 2;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
d[i][j] = 1e18;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
// if(i == j) continue;
d[i][j] = min(g[i][j], (ll)1e18 / mid) * mid - opt[i][j];
d[i][j] = min(d[i][j], (ll)1e18);
// d[i][i] = 0;
}
}
floyd(n);
bool good = false;
for(int i = 1; i <= n; ++i)
if(d[i][i] <= 0) good = true,last = i;
if(good) l = mid;
else r = mid;
}
cout << l;
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int32_t main()':
merchant.cpp:62:9: warning: variable 'last' set but not used [-Wunused-but-set-variable]
62 | int last = 0;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |