제출 #237875

#제출 시각아이디문제언어결과실행 시간메모리
237875grtValley (BOI19_valley)C++17
36 / 100
22 ms512 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 1000 + 10; const ll INF = 1e18; int n,s,q,root; int cost[nax]; vector<pi>V[nax]; bool is_shop[nax]; int ban; bool find_root; ll dist_to_shop; void dfs(int x,int p, ll d) { if(is_shop[x]) { dist_to_shop = min(dist_to_shop, d); } if(x == root) { find_root = 1; } for(auto nbh : V[x]) { if(nbh.ST != p && ban != nbh.ND) { dfs(nbh.ST, x, d + cost[nbh.ND]); } } } int main() {_ cin >> n >> s >> q >> root; for(int a,b,w,i=1; i<n; ++i) { cin >> a >> b >> w; V[a].PB({b,i}); V[b].PB({a,i}); cost[i] = w; } for(int a,i=1; i<=s ;++i) { cin >> a; is_shop[a] = 1; } for(int a,b,i=1; i<=q; ++i) { cin >> a >> b; ban = a; find_root = 0; dist_to_shop = INF; dfs(b, 0, 0); if(find_root) { cout << "escaped\n"; } else { if(dist_to_shop != INF) { cout << dist_to_shop << "\n"; } else { cout << "oo\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...