This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |