#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];
ll dist[mxN];
queue<int> q;
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], D[i]);
adj[B[i]].emplace_back(A[i], D[i]);
}
for(int i = 0; i < N; ++i) {
dist[i] = -1;
}
}
/* long long Query(int S, int X[], int T, int Y[]) { */
long long Query(signed S, signed X[], signed T, signed Y[]) {
/* for(int y : Y) { */
for(int i = 0; i < T; ++i) {
dist[Y[i]] = 0;
q.push(Y[i]);
}
while(!q.empty()) {
int a = q.front();
q.pop();
for(auto tmp : adj[a]) {
int b = tmp.first; ll w = tmp.second;
if(dist[b] != -1) continue;
dist[b] = dist[a] + w;
q.push(b);
}
}
ll res = -1;
for(int i = 0; i < S; ++i) {
if(dist[X[i]] != -1 && (res == - 1 || dist[X[i]] < res)) res = dist[X[i]];
}
for(int i = 0; i < n; ++i) dist[i] = -1;
return res;
}
Compilation message
factories.cpp:8:2: warning: #warning checkconstanst as per subtask [-Wcpp]
8 | #warning checkconstanst as per subtask
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
16984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |