Submission #1307036

#TimeUsernameProblemLanguageResultExecution timeMemory
1307036saken03Valley (BOI19_valley)C++20
23 / 100
67 ms11244 KiB
#include <iostream> #include <vector> #define pb push_back #define fi first #define se second using namespace std; const int N = 1e5 + 5; int n, s, q, e; pair<int, int> edge[N]; vector<int> g[N], shops; bool is_esc[N]; int in[N], out[N], clk, par[N]; void dfs(int v, int p = -1) { in[v] = ++clk; par[v] = p; for (int to : g[v]) { if (to != p) dfs(to, v); } out[v] = ++clk; } bool subtree_of(int a, int b) { if (in[a] <= in[b] && out[b] <= out[a]) return 1; return 0; } void solve() { cin >> n >> s >> q >> e; for (int i = 1; i < n; i++) { int a, b, c; cin >> a >> b >> c; g[a].pb(b); g[b].pb(a); edge[i] = {a, b}; } while (s--) { int c; cin >> c; shops.pb(c); } dfs(e); while (q--) { int i, r; cin >> i >> r; int a, b; a = edge[i].fi; b = edge[i].se; if (par[a] == b) swap(a, b); // a -> b (in tree) //cout << "a is " << a << ", b is " << b << '\n'; if (!subtree_of(b, r)) { cout << "escaped\n"; continue; } cout << "0\n"; } } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); 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...