#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma gcc-optimize("O3, unrolls-loops")
const int nx=2e5+5;
vector<pair<ll, ll>> g[nx];
void dfs(int u, int p, ll cw, vector<ll> &pa, vector<ll> &x)
{
pa[u]=p;
x[u]=cw;
for (auto [v, w]:g[u]) if (v!=p) dfs(v, u, cw+w, pa, x);
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
ll mx=0;
for (int i=0; i<N; i++) g[i].clear();
for (int i=0; i<N-1; i++) g[U[i]].push_back({V[i], W[i]}), g[V[i]].push_back({U[i], W[i]});
vector<ll> pa(N), pb(N), a(N), b(N);
dfs(X, X, 0, pa, a);
dfs(Y, Y, 0, pb, b);
for (int i=0; i<(1<<N); i++)
{
ll cst=0, res=0;
vector<int> vsa(N), vsb(N);
for (int j=0; j<N; j++)
{
if (i&(1<<j))
{
vsa[j]=vsb[j]=1;
cst+=max(a[j], b[j]);
res+=2;
int tmp=j;
while (tmp!=X)
{
if (!vsa[tmp]) vsa[tmp]=1, res++, cst+=a[tmp];
tmp=pa[tmp];
}
tmp=j;
while (tmp!=Y)
{
if (!vsb[tmp]) vsb[tmp]=1, res++, cst+=b[tmp];
tmp=pb[tmp];
}
}
}
if (cst>K) continue;
priority_queue<ll, vector<ll>, greater<ll>> pq;
for (int k=0; k<N; k++) if (!vsa[k]) pq.push(a[k]);
for (int k=0; k<N; k++) if (!vsb[k]) pq.push(b[k]);
while (!pq.empty()&&cst+pq.top()<=K) res++, cst+=pq.top(), pq.pop();
mx=max(mx, res);
}
return mx;
}
Compilation message
closing.cpp:7: warning: ignoring '#pragma gcc ' [-Wunknown-pragmas]
7 | #pragma gcc-optimize("O3, unrolls-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
37608 KB |
Output is correct |
2 |
Correct |
93 ms |
43712 KB |
Output is correct |
3 |
Execution timed out |
1012 ms |
7788 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5104 KB |
1st lines differ - on the 1st token, expected: '30', found: '33' |
4 |
Halted |
0 ms |
0 KB |
- |