#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 2e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, x, y, k, a[mxN];
vector<array<ll, 2> > g[mxN];
bool vis[mxN];
int BFS(const vector<int>& sources){
priority_queue<array<ll, 2>,
vector<array<ll, 2> >,
greater<array<ll, 2> > > pq;
for (int s : sources) pq.push({0, s});
int cnt = 0;
ll sum = 0;
while (pq.size()){
auto [d, s] = pq.top(); pq.pop();
if (sum + d > k) break;
sum += d;
cnt++;
vis[s] = 1;
a[s] = d;
for (auto [u, w] : g[s])
if (!vis[u])
pq.push({d + w, u});
}
return cnt;
}
int Solve1(){ return BFS({x, y}); }
int Next(int s, int p){
for (auto [u, w] : g[s])
if (u^p) return u;
return -1;
}
int Solve2(){
int s = 0;
for (; s < n; s++)
if (g[s].size() == 1)
break;
return -1;
}
int Solve3(){
return -1;
}
ll Dist(int s, int p, int d){
if (s == y) return d;
ll dist = 0;
for (auto [u, w] : g[s])
if (u^p) smax(dist, Dist(u, s, d + w));
return dist;
}
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W){
n = N; k = K;
x = X; y = Y;
for (int i = 0; i < n-1; i++){
g[U[i]].pb({V[i], W[i]});
g[V[i]].pb({U[i], W[i]});
}
if (Dist(x, -1, 0) > 2*k) return Solve1();
int mx = 0;
for (int i = 0; i < n; i++)
smax(mx, (int)g[i].size());
if (mx <= 2) return Solve2();
return Solve3();
}
Compilation message
closing.cpp: In function 'int Solve1()':
closing.cpp:60:27: warning: narrowing conversion of 'x' from 'long long int' to 'int' [-Wnarrowing]
60 | int Solve1(){ return BFS({x, y}); }
| ^
closing.cpp:60:27: warning: narrowing conversion of 'x' from 'long long int' to 'int' [-Wnarrowing]
closing.cpp:60:30: warning: narrowing conversion of 'y' from 'long long int' to 'int' [-Wnarrowing]
60 | int Solve1(){ return BFS({x, y}); }
| ^
closing.cpp:60:30: warning: narrowing conversion of 'y' from 'long long int' to 'int' [-Wnarrowing]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
44372 KB |
1st lines differ - on the 1st token, expected: '451', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |