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 "closing.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define pb push_back
#define eb emplace_back
ll distX[200005], distY[200005];
vector<ii> adj[200005];
void get_dist(int u, ll dist[], int e = -1) {
for (auto [v, w] : adj[u]) if (v != e) {
dist[v] = dist[u] + w;
get_dist(v, dist, u);
}
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
for (int i = 0; i < N - 1; i++) {
adj[U[i]].eb(V[i], W[i]);
adj[V[i]].eb(U[i], W[i]);
}
get_dist(X, distX);
get_dist(Y, distY);
int ret = 0;
for (int i = X; i >= 0; i--) {
for (int j = X; j < N; j++) {
for (int k = Y; k >= 0; k--) {
for (int l = Y; l < N; l++) {
ll cur = 0;
for (int a = 0; a < N; a++) {
bool cov1 = (i <= a && a <= j);
bool cov2 = (k <= a && a <= l);
if (cov1 && cov2) {
cur += max(distX[a], distY[a]);
} else if (cov1) {
cur += distX[a];
} else if (cov2) {
cur += distY[a];
}
}
if (cur <= K) {
ret = max(ret, j - i + 1 + l - k + 1);
}
}
}
}
}
for (int i = 0; i < N; i++) {
adj[i].clear();
distX[i] = distY[i] = 0;
}
return ret;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |