제출 #399016

#제출 시각아이디문제언어결과실행 시간메모리
399016Osama_Alkhodairy여행하는 상인 (APIO17_merchant)C++17
33 / 100
91 ms3892 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 101; const int K = 1001; const ll INF = (ll)1e18; int n, m, k; ll B[N][K], S[N][K], mx[N][N], dist[N][N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); for(int i = 1 ; i < N ; i++){ for(int j = 1 ; j < N ; j++){ dist[i][j] = INF; } } 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 = 0 ; i < m ; i++){ int x, y, z; cin >> x >> y >> z; dist[x][y] = z; } for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ for(int p = 1 ; p <= k ; p++){ if(B[i][p] != -1 && S[j][p] != -1){ mx[i][j] = max(mx[i][j], S[j][p] - B[i][p]); } } } } int l = 0, r = (int)1e9; while(l <= r){ int mid = (l + r) / 2; vector <vector <ll> > c(n + 1, vector <ll>(n + 1)); for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ c[i][j] = mx[i][j] - (dist[i][j] == INF ? INF : dist[i][j] * mid); } } for(int k = 1 ; k <= n ; k++){ for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ c[i][j] = max(c[i][j], c[i][k] + c[k][j]); } } } bool ok = 0; for(int i = 1 ; i <= n ; i++){ if(c[i][i] >= 0) ok = 1; } if(ok) l = mid + 1; else r = mid - 1; } cout << r << 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...