Submission #894058

#TimeUsernameProblemLanguageResultExecution timeMemory
894058vjudge1Railway (BOI17_railway)C++17
100 / 100
92 ms54100 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define P ord[in[n]=++cnt]=n,tb[cnt][0]={d,n}; #define N 100100 vector<pair<int,int>> adj[N]; int cnt, ord[2*N], sum[2*N], k, ans, in[N]; set<int> edges; pair<int,int> tb[2*N][20]; int lca(int l, int r) { if(l>r)swap(l,r); int x = 31-__builtin_clz(r-l+1); return min(tb[l][x],tb[r-(1<<x)+1][x]).second; } void dfs1(int n, int p, int d) { P for(auto [i,j]: adj[n]) if(i-p) dfs1(i,n,d+1),P; } void dfs2(int n, int p, int id) { for(auto [i,j]: adj[n]) if(i-p) dfs2(i,n,j),sum[n]+=sum[i]; if(sum[n]>=k) ans++, edges.insert(id); } void deputy() { int n; cin >> n; vector<int> v; for(int i = 0; i < n; i++) { int x; cin >> x; v.pb(in[x]); sum[x]++; } sort(v.begin(),v.end()); v.pb(v[0]); for(int i = 0; i < n; i++) sum[lca(v[i],v[i+1])]--; } int main() { cin.sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m >> k; for(int i = 1; i < n; i++) { int a, b; cin >> a >> b; adj[a].pb({b,i}); adj[b].pb({a,i}); } dfs1(1,0,1); for(int i = 1; i < 20; i++) for(int j = 1; j+(1<<i)<=2*n; j++) tb[j][i]=min(tb[j][i-1],tb[j+(1<<i-1)][i-1]); while(m--) deputy(); dfs2(1,0,0); cout << ans << '\n'; for(auto i: edges) cout << i << ' '; }

Compilation message (stderr)

railway.cpp: In function 'int main()':
railway.cpp:57:47: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   57 |             tb[j][i]=min(tb[j][i-1],tb[j+(1<<i-1)][i-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...
#Verdict Execution timeMemoryGrader output
Fetching results...