#include "factories.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 5e3 + 53;
ll d[N][N];
vector<ii> adj[N];
void dfs(int u, int pa, ll dis, int root)
{
d[root][u]=dis;
for (ii p : adj[u]) if (p.fi!=pa)
{
int v=p.fi,w=p.se;
dfs(v,u,dis+w,root);
}
}
void Init(int n, int A[], int B[], int D[]) {
for (int i=0; i<n-1; ++i)
{
int u=A[i],v=B[i],w=D[i];
adj[u].pb({v,w});
adj[v].pb({u,w});
}
for (int i=0; i<n; ++i) dfs(i,-1,0,i);
}
long long Query(int S, int X[], int T, int Y[]) {
ll ans=LLONG_MAX;
for (int i=0; i<S; ++i) for (int j=0; j<T; ++j)
{
int u=X[i],v=Y[j];
minimize(ans,d[u][v]);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |