# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147798 | HellAngel | Travelling Merchant (APIO17_merchant) | C++14 | 121 ms | 4216 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 int long long
const int maxn = 100 + 7;
const int maxk = 1e3 + 7;
const int Inf = 1e18;
using namespace std;
int dist[maxn][maxn], b[maxn][maxk], s[maxn][maxk], n, m, k, cost[maxn][maxn], gau[maxn][maxn];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
fill_n(&dist[0][0], maxn * maxn, Inf);
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];
dist[i][i] = 0;
}
for(int i = 1; i <= m; i++)
{
int u, v, c;
cin >> u >> v >> c;
dist[u][v] = min(dist[u][v], c);
}
for(int k = 1; k <= n ; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
int gau = dist[i][k] + dist[k][j];
gau = min(gau, Inf);
gau = max(gau, -Inf);
dist[i][j] = min(dist[i][j], gau);
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
for(int type = 1; type <= k; type++)
{
if(s[i][type] == -1 || b[j][type] == -1) continue;
cost[j][i] = max(cost[j][i], s[i][type] - b[j][type]);
}
}
}
int l = 0;
int r = 1e9;
while(l <= r)
{
int mid = l + r >> 1;
/// check(mid)
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(dist[i][j] != Inf)
gau[i][j] = mid * dist[i][j] - cost[i][j];
else
gau[i][j] = Inf;
}
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
int meo =gau[i][k] + gau[k][j];
meo = max(meo, -Inf);
meo = min(meo, Inf);
gau[i][j] = min(gau[i][j], meo);
}
}
}
bool cac = false;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(i == j) continue;
if(gau[i][j] + gau[j][i] <= 0) cac = true;
}
}
if(cac) l = mid + 1;
else r = mid - 1;
}
cout << r;
}
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... |