Submission #603110

#TimeUsernameProblemLanguageResultExecution timeMemory
603110AA_SurelyTravelling Merchant (APIO17_merchant)C++14
0 / 100
66 ms2064 KiB
#include <bits/stdc++.h>

#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)

#define WTF cout << "WTF" << endl

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define PB push_back

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, PII> PPI;

typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;

const int N = 100 + 7;
const int K = 1000 + 7;
const LL INF = 1e9 + 7;

#define B 0
#define S 1

LL n, m, k;
LL dist[N][N], obj[N][K][2], opt[N][N], adj[N][N], len[N];

void init() {
    cin >> n >> m >> k;
    F0R(i, n) F0R(j, k) cin >> obj[i][j][B] >> obj[i][j][S];
    
    F0R(i, n) F0R(j, n) dist[i][j] = INF;
    F0R(i, n) dist[i][i] = 0;

    F0R(i, m) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        dist[u][v] = w;
    }

    return;
}

void precalc() {
    F0R(x, n) F0R(i, n) F0R(j, n)
        dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);

    F0R(i, n) F0R(j, n) F0R(x, k) if (obj[i][x][B] != -1 && obj[j][x][S] != -1) 
        opt[i][j] = max(opt[i][j], - obj[i][x][B] + obj[j][x][S]);

    return;
}

bool check(LL m) {
    F0R(i, n) F0R(j, n) adj[i][j] = INF;
    F0R(i, n) adj[i][i] = 0;
    fill(len, len + n, INF);
    len[0] = 0;

    F0R(i, n) F0R(j, n) 
        if (dist[i][j] != INF) adj[i][j] = m * dist[i][j] - opt[i][j];

    //cout << "adj : " << endl; F0R(i, n) F0R(j, n) cout << adj[i][j] << " \n"[j == n - 1];
    
    F0R(go, n) F0R(i, n) F0R(j, n) if (adj[i][j] != INF) 
        len[j] = min(len[j], len[i] + adj[i][j]);

    F0R(i, n) F0R(j, n) if (adj[i][j] != INF)
        if (len[j] > len[i] + adj[i][j]) return 1;

    return 0;
}

int main() {
    IOS;

    init();
    precalc();

    LL l = 0, r = 1e11, mid;
    while(l < r) {
        mid = (l + r) >> 1;
        if (!check(mid)) r = mid;
        else l = mid + 1;
    }

    cout << l << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...