#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 = 5e5L + 10;
vector<pair<int, ll>> adj[mxN];
ll dist[mxN];
queue<int> q;
int n;
ll res = -1;
/* 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]));
}
for(int i = 0; i < N; ++i) {
dist[i] = -1;
}
}
void dfs(int x, int p) {
for(auto U : adj[x]) {
int y = U.first;
ll w = U.second;
if(y == p) continue;
dist[y] = dist[x] + w;
dfs(y, x);
}
}
long long Query(signed S, signed X[], signed T, signed Y[]) {
res = -1;
for(int i = 0; i < S; ++i) {
dist[X[i]] = 0;
dfs(X[i], -1);
for(int j = 0; j < T; ++j) {
if(dist[Y[j]] != -1 && (res > dist[Y[j]] || res == -1)) res = dist[Y[j]];
}
for(int j = 0; j < n; ++j) {
dist[j] = -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 |
Correct |
73 ms |
31068 KB |
Output is correct |
2 |
Execution timed out |
8023 ms |
35408 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
31064 KB |
Output is correct |
2 |
Execution timed out |
8098 ms |
64044 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
31068 KB |
Output is correct |
2 |
Execution timed out |
8023 ms |
35408 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |