#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int,ll>>>;
void dfs(int u, int fu, const Graph& g, vector<ll>& dists) {
for (auto [v, w] : g[u]) {
if (v == fu) continue;
assert(dists[v] < 0);
dists[v] = dists[u] + w;
dfs(v, u, g, dists);
}
}
vector<ll> get_dists(int u, const Graph& g) {
int n = g.size();
vector<ll> dists(n, -1);
dists[u] = 0;
dfs(u, -1, g, dists);
return dists;
}
// dists(x, y) > 2*k
int sub1(int n, const Graph& g, ll k,
const vector<ll>& distsX,
const vector<ll>& distsY) {
vector<ll> dists;
for (int i = 0; i < n; ++i) {
dists.push_back(min(distsX[i], distsY[i]));
}
sort(dists.begin(), dists.end());
int res = 0;
for (auto d : dists) {
if (d > k) break;
k -= d;
++res;
}
return res;
}
int max_score(int n, int X, int Y, long long K,
vector<int> U, vector<int> V, vector<int> W) {
Graph g(n);
assert(int(U.size()) == n-1);
assert(int(V.size()) == n-1);
assert(int(W.size()) == n-1);
for (int i = 0; i < n - 1; i++) {
int u = U[i];
int v = V[i];
int w = W[i];
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
auto distsX = get_dists(X, g);
auto distsY = get_dists(Y, g);
return sub1(n, g, K, distsX, distsY);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
30668 KB |
Output is correct |
2 |
Correct |
119 ms |
36808 KB |
Output is correct |
3 |
Correct |
65 ms |
3000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |