# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50120 | mohammad_kilani | Travelling Merchant (APIO17_merchant) | C++17 | 106 ms | 1660 KiB |
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>
using namespace std;
#define mod 1000000007
#define oo 1000000005
const int N = 150 , K = 1100;
int dist[N][N] , best[N][N];
long long cur[N][N];
int b[N][K] , s[N][K];
int n , m , k , u , v , w;
bool check(long long mid){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j) continue;
cur[i][j] = (long long)dist[i][j] * mid - best[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int l=1;l<=n;l++){
if(i != j && i != l)
cur[j][l] = min(cur[j][l] , cur[j][i] + cur[i][l]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i != j)
if(cur[i][j] + mid * dist[j][i] <= 0.00001)
return true;
}
}
return false;
}
int main() {
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i != j)
dist[i][j] = oo;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
scanf("%d%d",&b[i][j],&s[i][j]);
}
}
for(int i=0;i<m;i++){
scanf("%d%d%d",&u,&v,&w);
dist[u][v] = min(dist[u][v],w);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
dist[j][k] = min(dist[j][k],dist[j][i] + dist[i][k]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j) continue;
best[i][j] = -oo;
if(dist[i][j] >= oo) continue;
best[i][j] = 0;
for(int l=1;l<=k;l++){
if(b[i][l] != -1 && s[j][l] != -1)
best[i][j] = max(best[i][j], s[j][l] - b[i][l]);
}
}
}
long long low = 1 , high = oo , ans = 0 , mid = 0;
while(high >= low){
mid = (low + high) / 2;
if(check(mid)){
ans = mid;
low = mid + 1;
continue;
}
else
high = mid - 1;
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | 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... |