This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mxN = 110, mxK = 1010;
bool vis[mxN][mxK];
vector<pair<ll, ll>> adj[mxN];
vector<pair<ll, ll>> market[mxN];
ll N, M, K, ans;
void dfs(ll node, ll st, ll depth, ll pack, ll profit, ll time) {
if (node == st && depth) {
// cerr << profit << ' ' << time << endl;
return void(ans = max(ans, (ll)(profit/time)));
}
if (vis[node][pack+1])
return;
vis[node][pack+1] = 1;
if (~pack && ~market[node][pack].second) {
dfs(node, st, depth, -1, profit + market[node][pack].second, time);
}
if (!(~pack)) {
for (auto& c : adj[node]) {
for (ll i = 0; i < K; i++) {
if (~market[node][i].first)
dfs(c.first, st, depth+1, i, profit - market[node][i].first, time + c.second);
}
}
}
for (auto& c : adj[node]) {
dfs(c.first, st, depth+1, pack, profit, time + c.second);
}
}
void solve() {
cin >> N >> M >> K;
for (ll i = 1; i <= N; i++) {
for (ll j = 0; j < K; j++) {
ll b, s;
cin >> b >> s;
market[i].push_back({b, s});
}
}
for (ll i = 0; i < M; i++) {
ll u, v, t;
cin >> u >> v >> t;
adj[u].push_back({v, t});
}
for (ll i = 1; i <= N; i++) {
memset(vis, 0, sizeof vis);
dfs(i, i, 0, -1, 0, 0);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |