This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "factories.h"
#include "bits/stdc++.h"
using namespace std;
const char nl = '\n';
using ll = long long;
#warning checkconstanst as per subtask
const int mxN = 5e3L + 10;
vector<pair<int, ll>> adj[mxN];
int n;
/* void Init(int N, int A[], int B[], int D[]) { */
void Init(signed N, signed A[], signed B[], signed D[]) {
n = N;
for(int i = 0; i < N - 1; ++i) {
adj[A[i]].emplace_back(B[i], ll(D[i]));
adj[B[i]].emplace_back(A[i], ll(D[i]));
}
}
long long Query(signed S, signed X[], signed T, signed Y[]) {
ll dist[n];
for(int i = 0; i < n; ++i) dist[i] = -1;
priority_queue<pair<ll, int>> pq;
for(int i = 0; i < S; ++i) {
dist[X[i]] = 0;
pq.emplace(0, X[i]);
}
while(!pq.empty()) {
int a = pq.top().second;
ll d = -pq.top().first;
pq.pop();
if(dist[a] < d) continue;
for(auto U : adj[a]) {
int b = U.first; ll w = U.second;
if(dist[b] == -1 || dist[b] > d + w) {
dist[b] = d + w;
pq.emplace(-dist[b], b);
}
}
}
ll res = -1;
for(int i = 0; i < T; ++i) {
if(res == -1) res = dist[Y[i]];
else if(dist[Y[i]] != -1) res = min(res, dist[Y[i]]);
}
return res;
}
Compilation message (stderr)
factories.cpp:8:2: warning: #warning checkconstanst as per subtask [-Wcpp]
8 | #warning checkconstanst as per subtask
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |