#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pil = pair<int, lint>;
using pli = pair<lint, int>;
const int MAX_N = 2e5 + 5;
const lint INF = 5e18;
int n, x, y;
lint k;
vector<pil> adj[MAX_N];
bool seen[MAX_N];
lint min_dist[MAX_N];
priority_queue<pli, vector<pli>, greater<pli>> order;
void dijk(int s) {
for (int i = 0; i <= n - 1; i++) {
min_dist[i] = INF;
seen[i] = false;
}
min_dist[s] = 0;
order.push({0, s});
while (order.size()) {
int u = order.top().second;
order.pop();
if (seen[u]) continue;
seen[u] = true;
for (pil e : adj[u]) {
lint new_dist = min_dist[u] + e.second;
if (new_dist >= min_dist[e.first]) continue;
min_dist[e.first] = new_dist;
order.push({new_dist, e.first});
}
}
}
lint dist[MAX_N];
void precomp() {
dijk(x);
for (int i = 0; i <= n - 1; i++)
if (min_dist[i] <= k) dist[i] = min_dist[i];
dijk(y);
for (int i = 0; i <= n - 1; i++)
if (min_dist[i] <= k) dist[i] = min_dist[i];
}
bool taken[MAX_N];
set<pli> order2; // {dist, node}
void init() {
for (int i = 0; i <= n - 1; i++) {
adj[i].clear();
dist[i] = INF;
taken[i] = false;
}
order2.clear();
}
int max_score(int tmp_n, int tmp_x, int tmp_y, lint tmp_k, vector<int> edge1, vector<int> edge2, vector<int> edge3) {
n = tmp_n;
x = tmp_x;
y = tmp_y;
k = tmp_k;
init();
for (int i = 0; i <= n - 2; i++) {
adj[edge1[i]].push_back({edge2[i], edge3[i]});
adj[edge2[i]].push_back({edge1[i], edge3[i]});
}
precomp();
order2.insert({0, x});
order2.insert({0, y});
lint sum = 0;
while (order2.size()) {
int u = order2.begin()->second;
order2.erase(order2.begin());
if (sum + dist[u] > k) break;
taken[u] = true;
sum += dist[u];
for (pil e : adj[u]) {
if (taken[e.first]) continue;
if (order2.count({dist[e.first], e.first})) continue;
order2.insert({dist[e.first], e.first});
}
}
int ans = 0;
for (int i = 0; i <= n - 1; i++) ans += taken[i];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
27220 KB |
Output is correct |
2 |
Correct |
97 ms |
27340 KB |
Output is correct |
3 |
Correct |
64 ms |
13648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8284 KB |
1st lines differ - on the 1st token, expected: '6', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |