Submission #232044

# Submission time Handle Problem Language Result Execution time Memory
232044 2020-05-15T19:19:55 Z parsa_mobed Travelling Merchant (APIO17_merchant) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 101, K = 1001, inf = 2e9;
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++) 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] = min(dis[i][j], 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;
}

Compilation message

merchant.cpp: In function 'int32_t main()':
merchant.cpp:26:90: error: 'j' was not declared in this scope
     for (int i = 0; i < m; i++) {int u, v, w; cin >> u >> v >> w, dis[u][v] = min(dis[i][j], w);}
                                                                                          ^