Submission #881927

#TimeUsernameProblemLanguageResultExecution timeMemory
88192712345678Synchronization (JOI13_synchronization)C++17
30 / 100
58 ms23128 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, m, q, u, v, on[nx], x, dp[nx]; vector<pair<int, int>> d[nx], t[2*nx]; void dfs(int u, int p, int l) { dp[u]=1; for (auto [v, idx]:d[u]) { if (v==p||t[idx].empty()) continue; auto itr=lower_bound(t[idx].begin(), t[idx].end(), make_pair(l, INT_MAX)); if (itr==t[idx].begin()) continue; dfs(v, u, min(prev(itr)->second, l)); dp[u]+=dp[v]; } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>q; for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back({v, i}), d[v].push_back({u, i}); for (int i=1; i<=m; i++) { cin>>x; if (on[x]) t[x].push_back({on[x], i}), on[x]=0; else on[x]=i; } for (int i=1; i<n; i++) if (on[i]) t[i].push_back({on[i], m}); cin>>x; dfs(x, x, m); cout<<dp[x]; } /* 5 6 3 1 2 1 3 2 4 2 5 1 2 1 4 4 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...