Submission #1127167

#TimeUsernameProblemLanguageResultExecution timeMemory
1127167mispertionTravelling Merchant (APIO17_merchant)C++20
100 / 100
56 ms2120 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using ll = long long; #define int ll using ld = long double; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)x.size() const ld PI = 3.1415926535; const ld eps = 1e-9; const int N = 1e3 + 5; const int M = 7e6 + 1; ll mod = 998244353; const int infi = 1e9; const ll infl = 1e16; const int P = 31; int mult(int a, int b) { return a * 1LL * b % mod; } int sum(int a, int b) { if(a + b >= mod) return a + b - mod; if(a + b < 0) return a + b + mod; return a + b; } ll binpow(ll a, ll n) { if (n == 0) return 1; if (n % 2 == 1) { return binpow(a, n - 1) * a % (mod); } else { ll b = binpow(a, n / 2); return b * b % (mod); } } int n, m, k, b[101][1001], s[101][1001], d[101][101], fl[101][101]; bool ok(int m){ int td[n + 1][n + 1]; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) td[i][j] = infl; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(i == j) continue; if(d[i][j] == infl) continue; td[i][j] = d[i][j] * m - fl[i][j]; } } for(int k = 1; k <= n; k++){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(td[i][k] != infl && td[k][j] != infl) td[i][j] = min(td[i][j], td[i][k] + td[k][j]); } } } for(int i = 1; i <= n; i++){ if(td[i][i] <= 0) return true; } return false; } void solve() { 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++) d[i][j] = infl; for(int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; d[u][v] = w; } for(int k = 1; k <= n; k++){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++) if(d[i][k] != infl && d[k][j] != infl) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } int ans = 0; for(int i = 1; i <= n; i++){ for(int j = i + 1; j <= n; j++){ int mxbs = 0, mxsb = 0; for(int c = 1; c <= k; c++){ if(b[i][c] != -1 && s[j][c] != -1) mxbs = max(mxbs, s[j][c] - b[i][c]); if(s[i][c] != -1 && b[j][c] != -1) mxsb = max(mxsb, s[i][c] - b[j][c]); } fl[i][j] = mxbs; fl[j][i] = mxsb; } } int lo = 0, hi = 1e9+1; while(lo + 1 < hi){ int m = (lo + hi) / 2; if(ok(m)) lo = m; else hi = m; } cout << lo << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i = 1; i <= t; i ++){ solve(); } 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...