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 pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Edge{
int u, w, i;
};
const int MAXN = 2e5+100;
int N, S, Q, E, shop[MAXN];
vector<Edge> g[MAXN];
void dijkstra(int s, int ind){
vector<ll> d(N, LLONG_MAX);
d[s] = 0;
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({d[s], s});
while(!pq.empty()){
auto [dist, v] = pq.top();
pq.pop();
if(dist > d[v]) continue;
for(auto [u, w, i] : g[v]){
if(i == ind) continue;
if(d[u] > d[v] + w){
d[u] = d[v] + w;
pq.push({d[u], u});
}
}
}
if(d[E] != LLONG_MAX){
cout << "escaped\n";
} else{
ll ans = LLONG_MAX;
rep(i, 0, S){
ans = min(ans, d[shop[i]]);
}
if(ans != LLONG_MAX){
cout << ans << "\n";
} else{
cout << "oo\n";
}
}
}
void solve(){
cin >> N >> S >> Q >> E;
--E;
rep(i, 0, N - 1){
int u, v, w;
cin >> u >> v >> w;
--u, --v;
g[u].pb({v, w, i});
g[v].pb({u, w, i});
}
rep(i, 0, S){
cin >> shop[i];
--shop[i];
}
rep(q, 0, Q){
int i, v;
cin >> i >> v;
--i, --v;
dijkstra(v, i);
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
valley.cpp: In function 'void dijkstra(int, int)':
valley.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | auto [dist, v] = pq.top();
| ^
valley.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | for(auto [u, w, i] : g[v]){
| ^
# | 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... |