Submission #1148575

#TimeUsernameProblemLanguageResultExecution timeMemory
1148575adlinValley (BOI19_valley)C++20
0 / 100
38 ms9028 KiB
#include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const int maxn = 1e5 + 5; int n,s,q,e,a[maxn],x[maxn],y[maxn],z[maxn],c[maxn],z1[maxn],z2[maxn]; vector <pair<int,int>> g[maxn]; int d[maxn]; int xx; void dfs(int v, int u){ for(auto i : g[v]){ if(i.F == u) continue; if(min(i.F,v) == x[z1[xx]] && max(i.F,v) == y[z1[xx]]){ continue; } d[i.F] = d[v] + i.S; dfs(i.F,v); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s >> q >> e; for(int i = 1; i < n; i++){ cin >> x[i] >> y[i] >> z[i]; if(x[i] > y[i]) swap(x[i],y[i]); g[x[i]].pb({y[i],z[i]}); g[y[i]].pb({x[i],z[i]}); } for(int i = 1; i <= s; i++){ cin >> c[i]; } for(int i = 1; i <= q; i++){ cin >> z1[i] >> z2[i]; } if(n <= 1000 && q <= 1000){ for(int i = 1; i <= q; i++){ for(int j = 1; j <= n; j++) d[j] = -1; xx = i; d[z2[i]] = 0; dfs(z2[i],z2[i]); if(d[e] != -1){ cout << "escaped\n"; } else { int mn = 1e9; for(int j = 1; j <= s; j++){ if(d[c[j]] != -1) mn = min(mn, d[c[j]]); } if(mn == 1e9) cout << "oo\n"; else cout << mn << '\n'; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...