제출 #699816

#제출 시각아이디문제언어결과실행 시간메모리
699816Spade1여행하는 상인 (APIO17_merchant)C++14
100 / 100
83 ms4200 KiB
#include<bits/stdc++.h> #define pii pair<int, int> #define pII pair<pii, pii> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX #define sz(x) (int)x.size() using namespace std; const int N = 110; const int K = 1010; ll dis[N][N], dis2[N][N], prf[N][N]; ll s[N][K], b[N][K]; void solve() { int n, m, k; 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 = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) dis[i][j] = INF; for (int i = 1; i <= m; ++i) { int u, v, w; cin >> u >> v >> w; dis[u][v] = w; } for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) for (int l = 1; l <= k; ++l) { if (s[j][l] == -1 || b[i][l] == -1) continue; prf[i][j] = max(prf[i][j], s[j][l] - b[i][l]); } ll l = 0, r = 1e9; while (l < r) { ll mid = (l+r+1)/2; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) dis2[i][j] = mid*dis[i][j] - prf[i][j]; for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]); bool y = 0; for (int i = 1; i <= n; ++i) if (dis2[i][i] <= 0) y = 1; if (y) l = mid; else r = mid-1; } cout << l << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...