제출 #75808

#제출 시각아이디문제언어결과실행 시간메모리
75808tmwilliamlin168여행하는 상인 (APIO17_merchant)C++14
100 / 100
125 ms9500 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN=100, mxK=1000; int n, m, k, b[mxN][mxK], s[mxN][mxK], a[mxN][mxN]; ll d1[mxN][mxN], d2[mxN][mxN]; void fw(ll d[mxN][mxN]) { for(int k=0; k<n; ++k) for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) d[i][j]=min(d[i][k]+d[k][j], d[i][j]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for(int i=0; i<n; ++i) for(int j=0; j<k; ++j) cin >> b[i][j] >> s[i][j]; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) for(int l=0; l<k; ++l) if(b[i][l]!=-1&&s[j][l]!=-1) a[i][j]=max(s[j][l]-b[i][l], a[i][j]); // for(int i=0; i<n; ++i) { // for(int j=0; j<n; ++j) // cout << a[i][j] << " "; // cout << endl; // } memset(d1, 0x3F, sizeof(d1)); while(m--) { int v, w, t; cin >> v >> w >> t, --v, --w; d1[v][w]=t; } fw(d1); ll lb=1, rb=1e9; while(lb<=rb) { ll mb=(lb+rb)/2; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) d2[i][j]=mb*min(d1[i][j], LLONG_MAX/2/mb)-a[i][j]; fw(d2); bool ok=0; for(int i=0; i<n&&!ok; ++i) ok=d2[i][i]<=0; if(ok) lb=mb+1; else rb=mb-1; } cout << rb; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...