#include <bits/stdc++.h>
#include "closing.h"
using namespace std;
#define int long long
#define sz(a){ return (int)a.size(); }
const int INF=1e9;
vector<vector<pair<int,int>>> edges;
vector<int> dstX;
vector<int> dstY;
signed max_score(signed N, signed rootX, signed rootY, long long K, std::vector<signed> U, std::vector<signed> V, std::vector<signed> W){
vector<pair<int,int>> singl;
vector<pair<int,int>> doubl;
edges.clear();
dstX.clear();
edges.resize(N);
dstX.resize(N);
dstY.resize(N);
singl.resize(N);
doubl.resize(N);
for (int i = 0; i < N-1; i++)
{
edges[V[i]].push_back({U[i], W[i]});
edges[U[i]].push_back({V[i], W[i]});
}
if(rootX>rootY) swap(rootX, rootY);
vector<bool> visited(N);
queue<pair<int,int>> queue;
queue.push({rootX,0});
while(!queue.empty()){
int x=queue.front().first,w=queue.front().second; queue.pop();
if(visited[x]) continue;
visited[x]=true;
dstX[x]=w;
for (auto u: edges[x]) queue.push({u.first, u.second+w});
}
visited.clear();
visited.resize(N);
queue.push({rootY,0});
while(!queue.empty()){
int x=queue.front().first,w=queue.front().second; queue.pop();
if(visited[x]) continue;
visited[x]=true;
dstY[x]=w;
for (auto u: edges[x]) queue.push({u.first, u.second+w});
}
int mx=0;
for (int l1 = rootX; l1 >= 0; l1--)
{
for (int r1 = rootX; r1 < N; r1++)
{
for (int l2 = rootY; l2 >= 0; l2--)
{
for (int r2 = rootY; r2 < N; r2++)
{
if((r1-l1)+(r2-l2)+2<mx) continue;
int sum=0;
for (int i = 0; i < N; i++)
{
if(l1<=i&&r1>=i&&l2<=i&&r2>=i) sum+=max(dstX[i],dstY[i]);
else if(l1<=i&&r1>=i) sum+=dstX[i];
else if(l2<=i&&r2>=i) sum+=dstY[i];
}
if(sum>K) continue;
//cerr << l1 << " " << r1 << " " << l2 << " " << r2 << "\n";
mx=max((r1-l1)+(r2-l2)+2,mx);
}
}
}
}
return (int)mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1057 ms |
29524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
28 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
28 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
348 KB |
Output is correct |
13 |
Correct |
89 ms |
416 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
121 ms |
416 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
4 ms |
344 KB |
Output is correct |
19 |
Execution timed out |
1055 ms |
348 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
28 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
348 KB |
Output is correct |
13 |
Correct |
89 ms |
416 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
121 ms |
416 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
4 ms |
344 KB |
Output is correct |
19 |
Execution timed out |
1055 ms |
348 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |