이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |