# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1260732 | Sam_arvandi | 여행하는 상인 (APIO17_merchant) | C++20 | 40 ms | 840 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define FOR(i, j, n) for(ll i= 1; i<= n; i++)
#define ROF(i, n, j) for(ll i = n; i>= j; i--)
#define F first
#define S second
#define pb push_back
#define IOS ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define G(i, j) get<j-1>(i)
#define prll(x) cout << #x << ": " << x << endl
const ll mn = 100 + 5, inf = 1e9;
ll d[mn], y[mn][mn], a[mn][mn], b[mn][mn], f[mn][mn], c[mn][mn], D[mn][mn], q[mn];
bool mark[mn];
signed main()
{
IOS;
ll w, n, m, k, u, v;
cin >> n >> m >> k;
FOR(i, 1, n)
{
FOR(j, 1, k)
{
cin >> b[i][j] >> c[i][j];
if (b[i][j] == -1) b[i][j] = inf;
if (c[i][j] == -1) c[i][j] = -inf;
}
}
FOR(i,1, n)
{
FOR(j, 1, n)
{
y[i][j] = inf;
}
}
FOR(i, 1, m)
{
cin >> u >> v >> w;
y[u][v] = w;
}
FOR(i,1 , n)
{
FOR(j, 1, n)
{
f[i][j] = -inf;
FOR(w, 1, k)
{
f[i][j] = max(f[i][j], -b[i][w]+c[j][w]);
}
}
}
FOR(r, 1, n)
{
FOR(i, 1, n)
{
mark[i] = 0;
d[i] = inf;
}
d[r] = 0;
FOR(tmp, 1, n)
{
u = -1;
FOR(i, 1, n)
{
if (u == -1 and !mark[i]) u = i;
if (!mark[i] and d[u] > d[i]) u = i;
}
mark[u] = 1;
FOR(v, 1, n)
{
if (mark[v]) continue;
d[v] = min(d[v], d[u]+y[u][v]);
}
}
FOR(i, 1, n)
{
D[r][i] = d[i];
}
}
/*
FOR(i, 1, n)
{
FOR(j, 1, n)
{
cout << i << ' ' << j << ' ' << f[i][j] << endl;
}
}
cout <<"_----------------" << endl;
*/
ll L = -1, R = inf, mid;
while (L+1 != R)
{
mid = (L+R)/2;
mid--;
FOR(u, 1, n)
{
FOR(v, 1, n)
{
if (u == v)
{
a[u][v] = inf;
continue;
}
a[u][v] = f[u][v]- mid*D[u][v];
a[u][v] *= -1;
}
}
FOR(i, 1, n) d[i] = 0;
FOR(tmp, 1, n+1)
{
FOR(u, 1, n)
{
FOR(v, 1, n)
{
d[v] = min(d[v], d[u]+a[u][v]);
}
}
if (tmp == n)
{
FOR(u, 1, n) q[u] = d[u];
}
}
bool flag = 0;
FOR(u, 1, n)
{
if (q[u] != d[u]) flag = 1;
}
if (flag) L = mid+1;
else R = mid+1;
}
cout << L;
return 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... |