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>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
ll n,s,q,e;
vector<array<ll,3>>v[1000001];
vector<ll>shops;
ll dist[1000001];
void dijk(ll curr,ll del){
priority_queue<pair<ll,ll>>que;
que.push({0,curr});
while(que.size()){
auto [wei,x]=que.top();
que.pop();
if(dist[x]!=-1) continue;
wei=-wei;
dist[x]=wei;
for(auto [wei1,y,edge]:v[x]){
if(edge==del) continue;
que.push({-(wei+wei1),y});
}
}
}
void solve(){
memset(dist,-1,sizeof(dist));
cin>>n>>s>>q>>e;
for(int i=1;i<n;i++){
ll a,b,c;
cin>>a>>b>>c;
v[a].push_back({c,b,i});
v[b].push_back({c,a,i});
}
for(int i=0;i<s;i++){
ll a;
cin>>a;
shops.push_back(a);
}
while(q--){
ll del,idx;
cin>>del>>idx;
dijk(idx,del);
if(dist[e]!=-1){
co "escaped\n";
}
else{
ll least=1e18;
for(auto i:shops){
if(dist[i]!=-1) least=min(least,dist[i]);
}
if(least!=1e18) co least<<'\n';
else co "oo\n";
}
for(int i=1;i<=n;i++) dist[i]=-1;
}
}
int main()
{
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
return 0;
}
Compilation message (stderr)
valley.cpp: In function 'void dijk(long long int, long long int)':
valley.cpp:18:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
18 | auto [wei,x]=que.top();
| ^
valley.cpp:23:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
23 | for(auto [wei1,y,edge]:v[x]){
| ^
# | 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... |