#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long
#define ff first
#define ss second
const int N = 200005;
vector<pair<int, ll>> g[N];
void dfs(int v, int p, vector<ll> &D){
for(auto U: g[v]){
int u = U.ff;
if(u != p){
D[u] = D[v] + U.ss;
dfs(u, v, D);
}
}
}
int max_score(int n, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W){
for(int i = 0; i < n; ++i) g[i].clear();
for(int i = 0; i < n - 1; ++i){
g[V[i]].pb({U[i], W[i]});
g[U[i]].pb({V[i], W[i]});
}
vector<ll> D1(n), D2(n);
dfs(X, X, D1);
dfs(Y, Y, D2);
vector<array<ll, 3>> A;
K *= 2;
for(int i = 0; i < n; ++i){
A.pb({min(D1[i], D2[i]) * 2, i, 1});
A.pb({max(D1[i], D2[i]), i, 2});
}
int ans = 0;
vector<int> used(n);
sort(all(A));
for(int i = 0; i < A.size(); ++i){
int v = A[i][1];
if(used[v] == 2){
continue;
}
if(used[v] == 1){
if(K >= A[i][0] - min(D1[v], D2[v])){
K -= A[i][0] - min(D1[v], D2[v]);
used[v] = 2;
++ans;
}
}else{
if(K >= A[i][0]){
K -= A[i][0];
ans += A[i][2];
used[v] = A[i][2];
}
}
}
return ans;
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < A.size(); ++i){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
41904 KB |
Output is correct |
2 |
Correct |
129 ms |
47040 KB |
Output is correct |
3 |
Correct |
77 ms |
9300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
2nd lines differ - on the 1st token, expected: '3', found: '6' |
2 |
Halted |
0 ms |
0 KB |
- |