#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LSOne(S) ((S) & (-S))
const int mxN = 1e5+10;
vector<array<int, 2>> adj[mxN];
int timer = 0, tin[mxN], tout[mxN], p_edge[mxN];
int anc[mxN][20], bit[mxN+50], d[mxN];
void dfs(int node, int p) {
anc[node][0] = p;
tin[node] = ++timer;
for(int k = 1; k <= 18; k++) {
anc[node][k] = anc[anc[node][k-1]][k-1];
}
for(auto [it, i] : adj[node]) {
if(it == p) continue;
p_edge[it] = i;
d[it] = d[node]+1;
dfs(it, node);
}
tout[node] = timer;
}
void jmp(int &x, int dist) {
for(int k = 18; k >= 0; k--) {
if(dist & (1 << k)) x = anc[x][k];
}
}
int lca(int a, int b) {
if(d[b] > d[a]) swap(a, b);
jmp(a, d[a]-d[b]);
if(a == b) return a;
for(int k = 18; k >= 0; k--) {
if(anc[a][k] != anc[b][k]) {
a = anc[a][k];
b = anc[b][k];
}
}
return anc[a][0];
}
void upd(int x, int val) {
for(; x <= mxN; x += LSOne(x)) {
bit[x] += val;
}
}
int qry(int x) {
int ans = 0;
for(; x >= 1; x -= LSOne(x)) {
ans += bit[x];
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
for(int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back({b, i});
adj[b].push_back({a, i});
}
dfs(1, 0);
while(m--) {
int s;
cin >> s;
vector<int> v(s+1);
for(int i = 0; i < s; i++) {
cin >> v[i];
}
sort(v.begin(), v.end()-1, [&](int a, int b) {
return tin[a] < tin[b];
});
v[s] = v[0];
for(int i = 0; i < s; i++) {
int l = lca(v[i], v[i+1]);
upd(tin[v[i]], 1);
upd(tin[v[i+1]], 1);
upd(tin[l], -2);
}
}
vector<int> ans;
for(int i = 1; i <= n; i++) {
int now = qry(tout[i]) - qry(tin[i]-1);
if(now >= 2*k) ans.push_back(p_edge[i]);
}
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
for(auto it : ans) {
cout << it << ' ';
}
return 0;
}
# | 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... |