제출 #232040

#제출 시각아이디문제언어결과실행 시간메모리
232040parsa_mobed여행하는 상인 (APIO17_merchant)C++14
0 / 100
108 ms2040 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 101, K = 1001, inf = 1e17;
int cost[N][N], d[N][N], dis[N][N], B[N][K], S[N][K], n;

bool check(int x) {
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) d[i][j] = dis[i][j] * x - cost[i][j];
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) if (i != j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j && d[i][j] + d[j][i] <= 0) return 1;
    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int m, k; 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];
    for (int u = 1; u <= n; u++)
        for (int v = 1; v <= n; v++)
            for (int i = 1; i <= k; i++) if (B[u][i] != -1 && S[v][i] != -1)
                cost[u][v] = max(cost[u][v], S[v][i] - B[u][i]);
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) dis[i][j] = inf;
    for (int i = 0; i < m; i++) {int u, v, w; cin >> u >> v >> w, dis[u][v] = w;}
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    int dw = 0, up = inf;
    while (up - dw > 1) {
        int md = (up+dw)>>1;
        if (check(md)) dw = md;
        else up = md;
    }
    cout << dw << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...