#include "closing.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
priority_queue<pair<ll,int>> arr;
vector<vpi> paths(2e5+5);
vector<priority_queue<ll>> costs(2e5+5, priority_queue<ll>());
vi costindex(2e5+5,0);
void dfs(int pos,int cost,int prev){
for(pi edge:paths[pos]){
if(edge.F == prev)continue;
// cout << pos << " " << edge.F << " " << edge.S << " " << cost << " " << isX << endl;
costs[edge.F].push(-(edge.S+cost));
dfs(edge.F,edge.S+cost,pos);
}
}
int max_score(int N, int X, int Y, ll K,vi U, vi V, vi W)
{
arr = priority_queue<pair<ll,int>>();
paths = vector<vpi>(2e5+5);
costs = vector<priority_queue<ll>>(2e5+5, priority_queue<ll>());
costindex = vi(2e5+5,0);
FOR(i,0,N-1){
paths[U[i]].pb({V[i],W[i]});
paths[V[i]].pb({U[i],W[i]});
}
// vi visited(2e5+5);
dfs(X,0,-1);
dfs(Y,0,-1);
int ans = 2;
FOR(i,0,N){
if(!costs[i].empty()){
arr.push({costs[i].top(),i});
costs[i].pop();
}
}
while(K > 0){
if(arr.empty())break;
pair<ll,int> node = arr.top();arr.pop();
ll a = -node.F;
int pos = node.S;
if(!costs[pos].empty()){
ll diffcost = -costs[pos].top()-a;
costs[pos].pop();
arr.push({-diffcost,pos});
}
// cout << K << " " << a << " " << pos << endl;
if(K >= a){
K-=a;
ans++;
}else{
break;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
264 ms |
49372 KB |
1st lines differ - on the 1st token, expected: '451', found: '342912' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
18440 KB |
Output is correct |
2 |
Correct |
9 ms |
18440 KB |
Output is correct |
3 |
Correct |
10 ms |
18444 KB |
Output is correct |
4 |
Correct |
9 ms |
18440 KB |
Output is correct |
5 |
Incorrect |
11 ms |
18440 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
18440 KB |
Output is correct |
2 |
Correct |
9 ms |
18440 KB |
Output is correct |
3 |
Correct |
10 ms |
18444 KB |
Output is correct |
4 |
Correct |
9 ms |
18440 KB |
Output is correct |
5 |
Incorrect |
11 ms |
18440 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
18440 KB |
Output is correct |
2 |
Correct |
9 ms |
18440 KB |
Output is correct |
3 |
Correct |
10 ms |
18444 KB |
Output is correct |
4 |
Correct |
9 ms |
18440 KB |
Output is correct |
5 |
Incorrect |
11 ms |
18440 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
18440 KB |
2nd lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |