Submission #661153

#TimeUsernameProblemLanguageResultExecution timeMemory
661153KINGTravelling Merchant (APIO17_merchant)C++14
0 / 100
97 ms2196 KiB
#include<bits/stdc++.h> #define NOT_STONKS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define int long long using namespace std; const int maxn = 100 + 10, maxk = 1e3 + 10; //4e6 + 10; //3e5 + 10; const int mod = 1e9 + 7, inf = 1e18; //998244353; typedef long long ll; ll n, m, k, b[maxn][maxk], s[maxn][maxk], floyd[maxn][maxn], val[maxn][maxn], dis[maxn]; vector< pair<int, int> > G[maxn], adj[maxn]; bool f(ll x) { vector< array<ll, 3> > vec; fill(dis, dis + maxn, inf); dis[1] = 0; for (int v = 1; v <= n; v++) { for (int u = v + 1; u <= n; u++) { vec.push_back({ v, u, floyd[v][u] * x - val[v][u] }); vec.push_back({ u, v, floyd[u][v] * x - val[u][v] }); } } for (int i = 0; i < n; i++) for (auto [ u, v, w ] : vec) dis[v] = min(dis[v], dis[u] + w); for (auto [ u, v, w ] : vec) if (dis[v] > dis[u] + w) return true; return false; } ll tmp[maxn][maxn]; bool morgh(ll x) { memset(tmp, 63, sizeof tmp); for (int u = 1; u <= n; u++) for (int v = 1; v <= n; v++) if (u != v) tmp[u][v] = min(tmp[u][v], x * floyd[u][v] - val[u][v]); for (int k = 1; k <= n; k++) { for (int u = 1; u <= n; u++) { for (int v = 1; v <= n; v++) { tmp[u][v] = min(tmp[u][v], tmp[u][k] + tmp[k][v]); } } } for (int k = 1; k <= n; k++) { for (int u = 1; u <= n; u++) { for (int v = 1; v <= n; v++) { tmp[u][v] = min(tmp[u][v], tmp[u][k] + tmp[k][v]); } } } for (int i = 1; i <= n; i++) if (tmp[i][i] <= 0) return true; return false; } int32_t main() { NOT_STONKS; cin >> n >> m >> k; for (int i = 1; i <= n; i++) for (int j = 0; j < k; j++) { cin >> b[i][j] >> s[i][j]; } for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; adj[u].push_back({ v, w }); } memset(floyd, 63, sizeof floyd); for (int v = 1; v <= n; v++) for (auto [ u, w ] : adj[v]) floyd[v][u] = min(floyd[v][u], w); for (int k = 1; k <= n; k++) for (int v = 1; v <= n; v++) for (int u = 1; u <= n; u++) floyd[v][u] = min(floyd[v][u], floyd[v][k] + floyd[k][u]); for (int v = 1; v <= n; v++) { for (int u = v + 1; u <= n; u++) { for (int i = 0; i < k; i++) { if (s[u][i] != -1 && b[v][i] != -1) val[v][u] = max(val[v][u], s[u][i] - b[v][i]); if (s[v][i] != -1 && b[u][i] != -1) val[u][v] = max(val[u][v], s[v][i] - b[u][i]); } } } ll high = 1e10, low = -1, mid; while (high - low > 1) { mid = (high + low) >> 1; if (morgh(mid)) low = mid; else high = mid; } cout << low; return 0; }

Compilation message (stderr)

merchant.cpp: In function 'bool f(ll)':
merchant.cpp:25:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         for (auto [ u, v, w ] : vec)
      |                   ^
merchant.cpp:27:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |     for (auto [ u, v, w ] : vec) if (dis[v] > dis[u] + w)
      |               ^
merchant.cpp: In function 'int32_t main()':
merchant.cpp:72:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |         for (auto [ u, w ] : adj[v])
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...