#include "factories.h"
#include "bits/stdc++.h"
using namespace std;
const char nl = '\n';
/* #warning checkconstanst as per subtask */
#define int long long
const int mxN = 5e5L + 10;
vector<pair<int, int>> adj[mxN];
int 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; int w = tmp.second;
if(dist[b] != -1) continue;
dist[b] = dist[a] + w;
q.push(b);
}
}
int 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
31064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
31064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
31064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |