제출 #856799

#제출 시각아이디문제언어결과실행 시간메모리
856799Trisanu_DasValley (BOI19_valley)C++17
36 / 100
3037 ms10776 KiB
#include <bits/stdc++.h> using namespace std; #define pi pair<int, int> #define ll long long #define ff first #define ss second ll n, s, q, e, z, r, c[100005]; vector<pi> adj[100005]; pi rs[100005]; ll dfs(ll u, ll p){ ll ans = LLONG_MAX / 3; if(u == e) return -1; for(auto v : adj[u]){ if(v.ff == rs[z].ff && u == rs[z].ss) continue; if(v.ff == rs[z].ss && u == rs[z].ff) continue; if(v.ff != p){ ll res = dfs(v.ff, u); if(res == -1) return -1; ans = min(ans, res + v.ss); } } if(c[u]) return 0; return ans; } int main(){ cin >> n >> s >> q >> e; for(ll i = 0; i < n-1; i++){ int u, v, w; cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); rs[i] = {u, v}; } for(ll i = 0; i < s; i++){ cin >> z; c[z] = 1; } for(ll i = 0; i < q; i++){ cin >> z >> r; z--; ll ans = dfs(r, -1); if(ans == -1) cout << "escaped\n"; else if(ans >= LLONG_MAX / 3) cout << "oo\n"; else cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...