# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106198 | ekrem | Travelling Merchant (APIO17_merchant) | C++98 | 525 ms | 4088 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>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define orta ((bas+son+1)/2)
#define linf 10000000000000000ll
#define inf 1000000007
#define N 1005
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
ll n, m, k, mx, bas, son, a[N][N+N], d[105][105], dd[105][105];
bool yap(int x){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
if(i == j){
dd[i][i] = -linf;
continue;
}
mx = 0;
for(int y = 1; y <= k+k; y += 2)
if(a[i][y] != -1 and a[j][y + 1] != -1)
mx = max(mx, a[j][y + 1] - a[i][y]);
dd[i][j] = mx - x*d[i][j];
// cout << i << " " << j << " " << d[i][j] << " " << mx << endl;
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
dd[i][j] = max(dd[i][j], dd[i][k] + dd[k][j] );
// for(int i = 1; i <= n; i++)
// for(int j = 1; j <= n; j++)
// cout << i << " " << j << " " << dd[i][j] << endl;
for(int i = 1; i <= n; i++)
if(dd[i][i] >= 0)
return true;
return false;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%lld %lld %lld",&n ,&m ,&k);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= k+k; j++)
scanf("%lld",&a[i][j]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
d[i][j] = inf;
d[i][i] = 0;
}
for(int i = 1; i <= m; i++){
ll x, y, z;
scanf("%lld %lld %lld",&x ,&y ,&z);
d[x][y] = min(d[x][y], z);
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
// yap(2);
// cout << yap(4) << endl;
bas = 0, son = 1000000007;
while(bas < son){
if(yap(orta))
bas = orta;
else
son = orta - 1;
}
printf("%lld\n", bas);
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... |