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>
#define F first
#define S second
using namespace std;
const int N = 2e5 + 10;
int n , x , y;
long long dis[2][N] , k;
vector <pair<int , int>> adj[N];
void Dfs(int v , int ty , int p = -1)
{
//cout << v << " wtf: " << ty << " " << dis[ty][v] << endl;
for(auto u : adj[v]) if(u.F != p)
{
dis[ty][u.F] = dis[ty][v] + u.S;
Dfs(u.F , ty , v);
}
}
int max_score(int nn, int X, int Y, long long K,
vector<int> U, vector<int> V, vector<int> W)
{
n = nn;
x = X;
y = Y;
k = K;
for(int i = 0 ; i < n ; i++)
adj[i].clear();
for(int i = 0 ; i < n - 1 ; i++)
{
adj[U[i]].push_back(make_pair(V[i] , W[i]));
adj[V[i]].push_back(make_pair(U[i] , W[i]));
}
//cout << x << " " << y << endl;
dis[0][x] = 0;
Dfs(x , 0);
dis[1][y] = 0;
Dfs(y , 1);
vector <long long> all;
for(int i = 0 ; i < n ; i++)
{
//cout << i << " : " << dis[0][i] << " " << dis[1][i] << endl;
all.push_back(min(dis[0][i] , dis[1][i]));
}
sort(all.rbegin() , all.rend());
int ans = 0;
while(!all.empty() && k >= all.back())
{
k -= all.back();
all.pop_back();
ans++;
}
return ans;
}
# | 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... |