Submission #250743

#TimeUsernameProblemLanguageResultExecution timeMemory
250743balbitTravelling Merchant (APIO17_merchant)C++14
100 / 100
192 ms4600 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #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; ll B[102][1002], S[102][1002]; vector<pii> g[102]; ll d[102][1002]; bool bellmango(int start, int mid) { memset(d, 0x3f, sizeof d); d[start][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) { if (d[v][j] == 0x3f3f3f3f3f3f3f3f) continue; 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) { bug(mid, "No"); return 0; } } bug(mid, "Works"); return 1; } ll gdst[102][102]; ll deal[102][102]; __int128 F[102][102]; bool floydgo(int mid){ memset(F, 0x3f, sizeof F); for (int i = 0; i<n; ++i) F[i][i] = 0; for (int i = 0; i<n; ++i) { for (int j = 0; j<n; ++j) { F[i][j] = min(F[i][j], deal[i][j] + mid * (__int128)gdst[i][j]); } } for (int K = 0; K<n; ++K){ for (int i = 0; i<n; ++i) { for (int j = 0; j<n; ++j) { F[i][j] = min(F[i][j], F[i][K] + F[K][j]); } } } for (int i = 0; i<n; ++i) { if (F[i][i] < 0) return 1; for (int j = 0; j<n; ++j) { if (j != i && F[i][j] + F[j][i] <=0) { return 1; } } } return 0; } 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<n; ++i) { for (int j = 0; j<n; ++j) { for (int K = 1; K<=k; ++K) { if (B[i][K] != -1 && S[j][K] != -1) { deal[i][j] = min(deal[i][j], B[i][K] - S[j][K]); } } } } memset(gdst, 0x3f, sizeof gdst); for (int i =0 ; i<n; ++i) gdst[i][i] = 0; for (int i = 0; i<m; ++i) { int a,b,c; cin>>a>>b>>c; g[a-1].pb({b-1,c}); gdst[a-1][b-1] = min(gdst[a-1][b-1], (ll)c); } for (int K = 0; K<n; ++K){ for (int i = 0; i<n; ++i) { for (int j = 0; j<n; ++j) { gdst[i][j] = min(gdst[i][j], gdst[i][K] + gdst[K][j]); } } } int l = 0, r = 1e9+1; while (l!=r) { int mid = (l+r)/2; if (floydgo(mid)) { l = mid+1; }else{ r = mid; } bug(l,r); } cout<<max(l-1,0ll)<<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...