Submission #701645

#TimeUsernameProblemLanguageResultExecution timeMemory
701645sugartheanhSynchronization (JOI13_synchronization)C++14
30 / 100
84 ms23792 KiB
#include <bits/stdc++.h> using namespace std; #define dbg(x) cerr << #x << ": " << x << endl; #define ii pair<int,int> #define fi first #define se second const int MOD = 1e9 + 7; const int N = 2e5 + 5; int n,m,q,d[N],first[N],ans = 0; vector<ii>p[N],c[N]; bool on[N]; int getpos(int k,int last) { int l = 0,r = c[k].size()-1; int pos = -1; while(l <= r) { int mid = l + r >> 1; if(c[k][mid].fi < last) { pos = mid; l = mid + 1; } else r = mid - 1; } return pos; } void dfs(int x,int u,int last) { ans++; for(auto v : p[u]) { if(v.fi == x) continue; int pos = getpos(v.se, last); if(pos == -1) continue; dfs(u,v.fi ,min(last, c[v.se][pos].se)); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>q; for(int i = 1;i < n;i++) { int u,v; cin>>u>>v; p[u].push_back(ii(v,i)); p[v].push_back(ii(u,i)); } for(int i = 1;i <= m;i++) { int x; cin>>x; if(!on[x]) first[x] = i; else c[x].push_back(ii(first[x], i)); on[x] ^= 1; } for(int i = 1;i < n;i++) { if(on[i]) c[i].push_back(ii(first[i], m+1)); } while(q--) { int root; cin>>root; dfs(0,root,m+1); cout<<ans; } return 0; }

Compilation message (stderr)

synchronization.cpp: In function 'int getpos(int, int)':
synchronization.cpp:19:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |         int mid = l + r >> 1;
      |                   ~~^~~
#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...