제출 #100444

#제출 시각아이디문제언어결과실행 시간메모리
100444square1001여행하는 상인 (APIO17_merchant)C++14
100 / 100
954 ms3324 KiB
#include <vector> #include <iostream> #include <algorithm> using namespace std; const int inf = 1012345678; int main() { int N, M, K; cin >> N >> M >> K; vector<vector<int> > B(N, vector<int>(K)), S(N, vector<int>(K)); for(int i = 0; i < N; ++i) { for(int j = 0; j < K; ++j) { cin >> B[i][j] >> S[i][j]; } } vector<vector<int> > D(N, vector<int>(N, inf)); for(int i = 0; i < N; ++i) D[i][i] = 0; for(int i = 0; i < M; ++i) { int V, W, T; cin >> V >> W >> T; --V, --W; D[V][W] = T; } for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { for(int k = 0; k < N; ++k) { D[j][k] = min(D[j][k], D[j][i] + D[i][k]); } } } long long L = 0, R = inf; while(R - L > 1) { long long M = (L + R) / 2; vector<vector<long long> > C(N, vector<long long>(N, 1LL << 51)); for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { if(D[i][j] == inf) continue; C[i][j] = (long long)(D[i][j]) * M; for(int k = 0; k < K; ++k) { if(S[j][k] != -1 && B[i][k] != -1) { C[i][j] = min(C[i][j], (long long)(D[i][j]) * M - (S[j][k] - B[i][k])); } } } } for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { for(int k = 0; k < N; ++k) { C[j][k] = min(C[j][k], C[j][i] + C[i][k]); } } } bool ok = true; for(int i = 0; i < N; ++i) { if(C[i][i] < 0) ok = false; for(int j = 0; j < N; ++j) { if(i != j && C[i][j] + C[j][i] <= 0) ok = false; } } if(ok) R = M; else L = M; } cout << int(L) << 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...