Submission #250735

#TimeUsernameProblemLanguageResultExecution timeMemory
250735balbitTravelling Merchant (APIO17_merchant)C++14
0 / 100
513 ms3320 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

const int maxn = 2e5+5;

int n,m,k;

int B[102][1002], S[102][1002];
vector<pii> g[102];
ll d[102][1002];

bool go(int v, int mid) {
    memset(d, 0x3f, sizeof d);
    d[v][0] = 0;
    for (int cnt = 0; cnt<n*3; ++cnt) {
        bool upd = 0;
        for (int v = 0; v<n; ++v) {
            for (int j = 0; j<=k; ++j) {
                for (pii & p : g[v]) {
                    if (d[p.f][j] > d[v][j] + mid * (ll)p.s) {
                        d[p.f][j] = d[v][j] + mid * (ll)p.s; upd = 1;
                    }
                }
                if (j == 0) {
                    for (int j2 = 1; j2<=k; ++j2) {
                        if (B[v][j2] != -1 && d[v][j2] > d[v][j] + B[v][j2]) {
                            d[v][j2] = d[v][j] + B[v][j2]; upd = 1;
                        }
                    }
                }else{
                    if (S[v][j] != -1 && d[v][0] > d[v][j] - S[v][j]){
                        d[v][0] = d[v][j] - S[v][j]; upd = 1;
                    }

                }
            }
        }
        if (!upd) return 0;
    }
    return 1;
}

signed main(){
    IOS();
    cin>>n>>m>>k;
    for (int i = 0; i<n; ++i) {
        for (int j = 0; j<k*2; ++j) {
            cin>>(j%2==0?B:S)[i][(j/2)+1];
        }
    }
    for (int i = 0; i<m; ++i) {
        int a,b,c; cin>>a>>b>>c;
        g[a-1].pb({b-1,c});
    }
    int l = 0, r = 1e9;
    while (l!=r) {
        int mid = (l+r)/2;
        if (go(0,mid)) {
            l = mid+1;
        }else{
            r = mid;
        }
        bug(l,r);
    }
    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...