#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
int x, y, n;
struct Arista
{
int v;
long long w;
};
struct Nodo
{
vector <Arista> ady;
long long distX, distY;
};
struct Estado
{
long long p;
int idx;
};
vector <Nodo> tree(n);
void bfs(int root, int n)
{
queue <Estado> cola;
vector <bool> vis (n, false);
cola.push({0, root});
vis[root] = true;
while (!cola.empty())
{
Estado curr = cola.front();
cola.pop();
if (root == x)
{
tree[curr.idx].distX = curr.p;
}
if (root == y)
{
tree[curr.idx].distY = curr.p;
}
for (auto i : tree[curr.idx].ady)
{
if (!vis[i.v])
{
vis[i.v] = true;
cola.push({curr.p + i.w, i.v});
}
}
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
x = X; y = Y; n = N;
for (int i = 0; i < N-1; i++)
{
tree[U[i]].ady.push_back({V[i], W[i]});
tree[V[i]].ady.push_back({U[i], W[i]});
}
bfs(X, N);
bfs(Y, N);
int resp = N;
long long sum = 0;
queue <long long> pq;
for (auto i : tree)
{
pq.push(min(i.distX, i.distY));
sum += (long long)min(i.distX, i.distY);
}
while (sum > K)
{
sum -= pq.front();
pq.pop();
resp--;
}
return resp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
48 ms |
10068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |