#include "closing.h"
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<math.h>
#include<vector>
#include<stdio.h>
#include<utility>
#include<iomanip>
#include<string.h>
#include<limits.h>
#include<algorithm>
#include<functional>
#include<unordered_map>
using namespace std;
#define ss second
#define ff first
#define endl '\n'
vector<pair<long long,int> > f,s;
vector<vector<pair<int,int> > > g;
void dfs1(int a, int p, long long w){
f.push_back({w,a});
for(auto node: g[a]){
if(node.ff!=p){
dfs1(node.ff,a,w+node.ss);
}
}
}
void dfs2(int a, int p, long long w){
s.push_back({w,a});
for(auto node: g[a]){
if(node.ff!=p){
dfs2(node.ff,a,w+node.ss);
}
}
}
int max_score(int n, int x, int y, long long k, vector<int> u, vector<int> v, vector<int> w){
f.clear(),s.clear();
g.clear(),g.resize(n);
for(int i=0; i<w.size(); i++){
g[u[i]].push_back({v[i],w[i]});
g[v[i]].push_back({u[i],w[i]});
}
dfs1(x,-1,0);
dfs2(y,-1,0);
sort(f.begin(),f.end());
sort(s.begin(),s.end());
bool ok=0;
int ans=0,cur=0;
long long sum=0;
vector<long long> vis(n,-1);
for(auto i: f){
if(sum+i.ff<=k){
cur++;
sum+=i.ff;
vis[i.ss]=i.ff;
if(i.ss==y) ok=1;
int cnt=cur;
long long tmp=sum;
for(auto j: s){
if(tmp+j.ff<=k){
if(vis[j.ss]==-1){
// if(ok) cnt+=2;
cnt++;
tmp+=j.ff;
}else{
cnt++;
if(vis[j.ss]<j.ff) tmp+=j.ff-vis[j.ss];
}
}
}
ans=max(ans,cnt);
}
}
return ans;
}
// int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// int T=1;
// // cin>>T;
// while(T--){
// int n,x,y,k; cin>>n>>x>>y>>k;
// vector<int> u(n-1),v(n-1),w(n-1);
// for(int i=0; i<n-1; i++) cin>>u[i]>>v[i]>>w[i];
// cout<<max_score(n,x,y,k,u,v,w)<<endl;
// }
// return 0;
// }
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:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0; i<w.size(); i++){
| ~^~~~~~~~~
closing.cpp:53:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
53 | bool ok=0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
96 ms |
33728 KB |
Output is correct |
2 |
Correct |
120 ms |
38600 KB |
Output is correct |
3 |
Correct |
52 ms |
2916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
5 |
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 |
- |