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 int long long
#define endl "\n"
int n,S,E,q,U,V,x,l,mn,flag;
vector <array<int,2>> v[100001],edges;
priority_queue <array<int,2>> qu;
int shops[100001];
void dfs(int i,int last,int sum){
if(i==E){
flag=1;
return;
}
if(shops[i]==1) mn=min(mn,sum);
for(auto [j,c]:v[i]){
if((i==U&&j==V)||(i==V&&j==U)||j==last) continue;
dfs(j,i,sum+c);
}
return;
}
void calc1(){
while(q--){
flag=0;
mn=100000000000000000;
cin>>l>>x;
U=edges[l-1][0];
V=edges[l-1][1];
dfs(x,0,0);
if(flag==1) cout<<"escaped"<<endl;
else if(mn!=100000000000000000) cout<<mn<<endl;
else cout<<"oo"<<endl;
}
}
signed main()
{
cin>>n>>S>>q>>E;
for(int i=0;i<n-1;i++){
int a,b,c;
cin>>a>>b>>c;
v[a].push_back({b,c});
v[b].push_back({a,c});
edges.push_back({a,b});
}
for(int i=0;i<S;i++){
int a;
cin>>a;
shops[a]=1;
}
calc1();
return 0;
}
Compilation message (stderr)
valley.cpp: In function 'void dfs(long long int, long long int, long long int)':
valley.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
15 | for(auto [j,c]:v[i]){
| ^
# | 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... |