#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
using namespace std;
const int maxn = 1e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, s, q, e, a[maxn], b[maxn], w[maxn], is[maxn];
vector < pair < int, int> > g[maxn];
int par[maxn];
long long block, ans, pos;
void dfs(int beg, int from, long long h)
{
if(is[beg])ans = h;
if(beg == e)pos = 1;
for (auto &[nb, index]: g[beg])
{
if(nb == from)continue;
if(block == index)continue;
dfs(nb, beg, h + w[index]);
}
}
int main()
{
speed();
cin >> n >> s >> q >> e;
for (int i = 1; i < n; ++ i)
{
cin >> a[i] >> b[i] >> w[i];
g[a[i]].pb(make_pair(b[i], i));
g[b[i]].pb(make_pair(a[i], i));
}
for (int i = 1; i <= s; ++ i)
{
int x;
cin >> x;
is[x] = 1;
}
for (int i = 1; i <= q; ++ i)
{
int ed, st;
cin >> ed >> st;
block = ed;
pos = 0;
ans = 1e17;
dfs(st, -1, 0);
if(pos)cout << "escaped" << endl;
else if(ans != 1e17)cout << ans << endl;
else cout << "oo" << endl;
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |