#include "closing.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> II;
const int N = 2e5 + 30, logN = 22;
const int MOD[2] = {998244353, 1000000007};
const int block = 20;
const ll inf = 2e9;
const ll INF = 1e18;
#define ms(s, n) memset(s, n, sizeof(s))
#define sz(a) (int) ((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define point II
#define X first
#define Y second
inline ll sqr(int x) {return x * 1ll * x;}
inline int fpow(ll n, ll k, int p) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline void addmod(int& a, int val, int p) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p) {return (ll) a * b % p;}
vector<II> g[N];
vector<ll> op;
void dfs(int u, int p, ll dist){
op.push_back(dist);
for(auto x : g[u]){
int v = x.first, w = x.second;
if(v == p) continue;
dfs(v, u, dist + w);
}
}
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(int i = 0; i < n; i ++) g[i].clear();
for(int i = 0; i < n - 1; i ++){
g[U[i]].push_back(II(V[i], W[i]));
g[V[i]].push_back(II(U[i], W[i]));
}
dfs(x, 0, 0);
dfs(y, 0, 0);
sort(op.begin(), op.end());
for(int i = 0; i < op.size() && k > 0; i ++){
if(k < op[i]) return i;
k -= op[i];
}
return op.size();
}
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:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i = 0; i < op.size() && k > 0; i ++){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
30400 KB |
Output is correct |
2 |
Correct |
117 ms |
33940 KB |
Output is correct |
3 |
Execution timed out |
1073 ms |
12248 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |