#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;
}
}
for (int j=0; j<N; j++)
{
if (i&(1<<j))
{
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 |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
37572 KB |
Output is correct |
2 |
Correct |
97 ms |
43716 KB |
Output is correct |
3 |
Execution timed out |
1016 ms |
8016 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
272 ms |
4956 KB |
Output is correct |
3 |
Correct |
350 ms |
4952 KB |
Output is correct |
4 |
Correct |
369 ms |
4956 KB |
Output is correct |
5 |
Correct |
161 ms |
4952 KB |
Output is correct |
6 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
272 ms |
4956 KB |
Output is correct |
3 |
Correct |
350 ms |
4952 KB |
Output is correct |
4 |
Correct |
369 ms |
4956 KB |
Output is correct |
5 |
Correct |
161 ms |
4952 KB |
Output is correct |
6 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
272 ms |
4956 KB |
Output is correct |
3 |
Correct |
350 ms |
4952 KB |
Output is correct |
4 |
Correct |
369 ms |
4956 KB |
Output is correct |
5 |
Correct |
161 ms |
4952 KB |
Output is correct |
6 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
272 ms |
4956 KB |
Output is correct |
4 |
Correct |
350 ms |
4952 KB |
Output is correct |
5 |
Correct |
369 ms |
4956 KB |
Output is correct |
6 |
Correct |
161 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
5208 KB |
Output is correct |
10 |
Correct |
56 ms |
4956 KB |
Output is correct |
11 |
Correct |
127 ms |
4956 KB |
Output is correct |
12 |
Correct |
8 ms |
4956 KB |
Output is correct |
13 |
Correct |
240 ms |
4880 KB |
Output is correct |
14 |
Correct |
213 ms |
4952 KB |
Output is correct |
15 |
Correct |
60 ms |
4956 KB |
Output is correct |
16 |
Correct |
87 ms |
4952 KB |
Output is correct |
17 |
Correct |
57 ms |
4956 KB |
Output is correct |
18 |
Correct |
117 ms |
4956 KB |
Output is correct |
19 |
Correct |
248 ms |
5108 KB |
Output is correct |
20 |
Correct |
104 ms |
5116 KB |
Output is correct |
21 |
Correct |
58 ms |
4952 KB |
Output is correct |
22 |
Correct |
347 ms |
5108 KB |
Output is correct |
23 |
Correct |
359 ms |
4952 KB |
Output is correct |
24 |
Correct |
52 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
272 ms |
4956 KB |
Output is correct |
4 |
Correct |
350 ms |
4952 KB |
Output is correct |
5 |
Correct |
369 ms |
4956 KB |
Output is correct |
6 |
Correct |
161 ms |
4952 KB |
Output is correct |
7 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
272 ms |
4956 KB |
Output is correct |
4 |
Correct |
350 ms |
4952 KB |
Output is correct |
5 |
Correct |
369 ms |
4956 KB |
Output is correct |
6 |
Correct |
161 ms |
4952 KB |
Output is correct |
7 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
272 ms |
4956 KB |
Output is correct |
4 |
Correct |
350 ms |
4952 KB |
Output is correct |
5 |
Correct |
369 ms |
4956 KB |
Output is correct |
6 |
Correct |
161 ms |
4952 KB |
Output is correct |
7 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
272 ms |
4956 KB |
Output is correct |
4 |
Correct |
350 ms |
4952 KB |
Output is correct |
5 |
Correct |
369 ms |
4956 KB |
Output is correct |
6 |
Correct |
161 ms |
4952 KB |
Output is correct |
7 |
Incorrect |
255 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '96', found: '90' |
8 |
Halted |
0 ms |
0 KB |
- |