#include "closing.h"
#include <bits/stdc++.h>
#define MAX 200005
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int visited[MAX];
vector<pii> graph[MAX];
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
for(int i = 0; i < N; ++i) visited[i] = 0;
for(int i = 0; i < N; ++i) graph[i].clear();
for(int i = 0; i < N - 1; ++i) {
graph[U[i]].push_back({V[i], W[i]});
graph[V[i]].push_back({U[i], W[i]});
}
int ans = 0;
priority_queue<pair<ll, int> > pq;
pq.push({0, X}); pq.push({0, Y});
while(!pq.empty()) {
int node = pq.top().second;
ll dist = -pq.top().first;
pq.pop();
if(visited[node]) continue;
visited[node] = 1;
if(dist > K) break;
K -= dist; ++ans;
for(auto [v, w] : graph[node]) pq.push({-(w + dist), v});
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
17968 KB |
Output is correct |
2 |
Correct |
65 ms |
20560 KB |
Output is correct |
3 |
Correct |
45 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '30', found: '17' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |