This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,s,q,e;
cin>>n>>s>>q>>e;
vector<array<ll,3>>adj[n+5];
vector<pair<ll,ll>>edge;
for(ll i=1;i<n;i++){//edge
ll a,b,w;
cin>>a>>b>>w;
adj[a].pb({b,w,i});
adj[b].pb({a,w,i});
}
vector<bool>shop(n+5,0);
for(ll i=1;i<=s;i++){//shop
ll c;
cin>>c;
shop[c]=true;
}
while(q--){
ll I,r;
cin>>I>>r;
bool can=false;
ll mn=1e18,dist=0;
function <void(ll,ll)> dfs=[&](ll x,ll p){
if(x==e){
can=true;
return;
}
if(shop[x]==true){
mn=min(mn,dist);
}
for(auto [y,w,j]:adj[x]){
if(j!=I&&y!=p){
dist+=w;
dfs(y,x);
dist-=w;
}
}
};
dfs(r,-1);
if(can){
cout<<"escaped\n";
}
else if(mn<1e18){
cout<<mn<<"\n";
}
else{
cout<<"oo\n";
}
}
}
# | 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... |