Submission #1261644

#TimeUsernameProblemLanguageResultExecution timeMemory
1261644antonn여행하는 상인 (APIO17_merchant)C++20
0 / 100
22 ms2052 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100 + 7;
const int K = 1000 + 7;

int n, m, k;
vector<pair<int, int>> g[N];
ll b[N][K], s[N][K];

vector<ll> get_dist(int u) {
    vector<ll> dist(n + 1, 1e18);
    vector<bool> vis(n + 1);
    priority_queue<pair<ll, int>> pq;
    pq.push({0, u});
    dist[u] = 0;
    while (!pq.empty()) {
        int u = pq.top().second;
        pq.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        for (auto [v, c] : g[u]) {
            if (dist[u] + c < dist[v]) {
                dist[v] = dist[u] + c;
                pq.push({-dist[v], v});
            }
        }
    }
    return dist;
}

ll give(int x, int y) {
    ll ans = 0;
    for (int i = 1; i <= k; ++i) if (s[y][i] != -1 && b[x][i] != -1) ans = max(ans, s[y][i] - b[x][i]);
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    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 i = 1; i <= m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    vector<vector<ll>> dist(n + 1);
    for (int i = 1; i <= n; ++i) dist[i] = get_dist(i);
    vector<vector<ll>> g(n + 1, vector<ll>(n + 1));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            g[i][j] = give(i, j);
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) {
                if (i != j && j != k && k != i) {
                    ans = max(ans, (g[i][j] + g[j][k]) / (dist[i][j] + dist[j][k] + dist[k][i]));
                }
            }
        }
    }
    cout << ans << "\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...