#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<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<ll> arrx,arry;
vector<vpi> paths(2e5+5);
void dfs(int pos,int cost,int prev,bool isX){
for(pi edge:paths[pos]){
if(edge.F == prev)continue;
// cout << pos << " " << edge.F << " " << edge.S << " " << cost << " " << isX << endl;
if(isX){
arrx.push(-(edge.S+cost));
dfs(edge.F,edge.S+cost,pos,isX);
}else{
arrx.push(-(edge.S+cost));
dfs(edge.F,edge.S+cost,pos,isX);
}
}
}
int max_score(int N, int X, int Y, ll K,vi U, vi V, vi W)
{
arrx = priority_queue<ll>();
arry = priority_queue<ll>();
paths = vector<vpi>(2e5+5);
FOR(i,0,N-1){
paths[U[i]].pb({V[i],W[i]});
paths[V[i]].pb({U[i],W[i]});
}
dfs(X,0,-1,1);
dfs(Y,0,-1,0);
int ans = 2;
while(K > 0){
ll a = 1e18;
int b = 0;
if(!arrx.empty()){
a = -arrx.top();
b = 1;
}
if(!arry.empty()){
if(a>-arry.top()){
a = -arry.top();
b = 2;
}
}
// cout << b << " " << a << " " << K << endl;
if(b == 0)break;
if(b == 1)arrx.pop();
if(b == 2)arry.pop();
if(K >= a){
K-=a;
ans++;
}else{
break;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
144 ms |
34264 KB |
1st lines differ - on the 1st token, expected: '451', found: '400000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Incorrect |
4 ms |
9820 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Incorrect |
4 ms |
9820 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Incorrect |
4 ms |
9820 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9816 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |