이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ff first
#define ss second
using namespace std;
const int N=1e6+7;
vector <pair <ll,ll>> g[N];
ll a[N], b[N];
bool u[N];
void dfs(ll v, ll p, ll l){
u[v]=1;
for (auto it:g[v]){
if (it.ff != p && it.ss != l){
dfs(it.ff, v, l);
}
}
return ;
}
int main()
{
ll n, s, q, e;
cin >> n >> s >> q >> e;
for (int i=1;i<n;i++){
int x, y;
cin >> x >> y >> a[i];
g[x].push_back({y, i});
g[y].push_back({x, i});
}
map <ll,ll> mp;
for (int i=1;i<=s;i++) cin >> b[i], mp[b[i]]++;
while (q--){
int l, r;
cin >> l >> r;
dfs(r, 0, l);
if (u[e]){
cout <<"escaped\n";
fill(u, u+n+1, 0);
}
else {
queue <ll> q;
vector <ll> dc(n+1, 1e9);
for (int i=1;i<=s;i++) {
if (u[b[i]]) q.push(b[i]), dc[b[i]]=0;
}
while (!q.empty()){
int x=q.front();
q.pop();
for (auto l:g[x]){
if (dc[l.ff] >= dc[x]+a[l.ss]){
dc[l.ff]=dc[x]+a[l.ss];
q.push(l.ff);
}
}
}
if (dc[r] == 1e9) cout << "oo\n";
else cout << dc[r] <<"\n";
fill(u, u+n+1, 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... |