Submission #383333

#TimeUsernameProblemLanguageResultExecution timeMemory
383333SaynaaTravelling Merchant (APIO17_merchant)C++17
21 / 100
131 ms896 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 100 + 10; const ll MAX = LLONG_MAX/2; int n, m, pf; ll mat[MAXN][MAXN], tmp[MAXN][MAXN], b[MAXN][MAXN], s[MAXN][MAXN], res[MAXN][MAXN]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m >> pf; for(int i = 0; i < n; i ++){ fill(mat[i], mat[i] + n, MAX); for(int j = 0; j < pf; j ++) cin >> b[i][j] >> s[i][j]; } for(int i = 0; i < m; i ++){ int u, v; ll w; cin >> u >> v >> w, u --, v --; mat[u][v] = w; } for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) for(int t = 0; t < n; t ++) mat[j][t] = min(mat[j][t], mat[j][i] + mat[i][t]); for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) for(int t = 0; t < pf; t ++) if( s[j][t] != -1 && b[i][t] != -1) res[i][j] = max(res[i][j], s[j][t] - b[i][t]); ll l = 1, r = MAX, ans = MAX; while( l <= r){ ll mid = (l + r)/2; for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) tmp[i][j] = mid*min(mat[i][j], MAX/mid) - res[i][j]; for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) for(int t = 0; t < n; t ++) tmp[j][t] = min(tmp[j][t], tmp[j][i] + tmp[i][t]); bool dor = false; for(int i = 0; i < n; i ++) if( tmp[i][i] <= 0) dor = true; if( dor ) l = mid + 1; else r = mid - 1, ans = min(ans, mid); } cout << r << endl; 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...