This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
long long u[200005],d[400005],i,j,ds,m,ans,sm;
vector <pair<long long,long long> > v[200005];
void dfs(long long g){
u[g]=1;
for (int j=0; j<v[g].size(); j++)
if (u[v[g][j].first]==0){
m++; ds+=v[g][j].second; d[m]=ds;
dfs(v[g][j].first); ds-=v[g][j].second;
}
}
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 (i=0; i<N; i++){u[i]=0; v[i].clear();}
for (i=0; i<N-1; i++){
v[U[i]].push_back({V[i],W[i]});
v[V[i]].push_back({U[i],W[i]});
}
ds=m=d[0]=0; dfs(X);
for (i=0; i<N; i++) u[i]=0;
m++; ds=d[m]=0; dfs(Y);
sort (d,d+m+1);
ans=sm=0;
for (i=0; i<m && sm+d[i]<=K; i++){
sm+=d[i]; ans++;
}
return ans;
}
Compilation message (stderr)
closing.cpp: In function 'void dfs(long long int)':
closing.cpp:8:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int j=0; j<v[g].size(); j++)
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |