#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
const int lim=3e3+100;
#else
const int lim=1e3+3;
#endif
const int lglim=18;
#include "bits/stdc++.h"
using namespace std;
//#define int int64_t
#define pb push_back
const int mod=998244353;
//const int mod=(1ll<<61)-1;
using pii=pair<int,int>;
int n,m,k;
int tin[lim],tout[lim],dep[lim],tt=0;
int lift[lglim][lim];
vector<pii>v[lim];
int pare[lim];
inline void tour(int node,int par){
tin[node]=tt++;
dep[node]=dep[par]-1;
lift[0][node]=par;
int i=1;
while(i<lglim&&(lift[i][node]=lift[i-1][lift[i-1][node]]))i++;
for(auto [j,c]:v[node]){
if(j^par){
pare[j]=c;
tour(j,node);
}
}
tout[node]=tt-1;
}
inline int lca(int x,int y){
if(dep[y]<dep[x])swap(x,y);
if(dep[x]<dep[y]){
for(int i=lglim-1;0<=i;i--){
if(dep[x]+(1<<i)<=dep[y]){
x=lift[i][x];
}
if(dep[x]==dep[y])break;
}
}
if(x==y)return x;
for(int i=lglim-1;0<=i;i--){
if(lift[i][x]^lift[i][y]){
x=lift[i][x];
y=lift[i][y];
}
}
return lift[0][x];
}
int val[lim];
vector<int>ans;
inline int dfs(int node,int par){
for(auto [j,c]:v[node]){
if(j^par){
val[node]+=dfs(j,node);
}
}
if(k<=val[node]){
ans.pb(pare[node]);
}
return val[node];
}
inline void solve(){
cin>>n>>m>>k;
for(int i=1;i<=n-1;i++){
int x,y;
cin>>x>>y;
v[x].pb({y,i});
v[y].pb({x,i});
}
tour(1,0);
for(int r=0;r<m;r++){
int s;
cin>>s;
vector<int>inds;
for(int i=0;i<s;i++){
int tem;
cin>>tem;
inds.pb(tem);
val[tem]++;
}
sort(inds.begin(),inds.end(),[&](int i,int j) -> bool {
return tin[i]<tin[j];
});
for(int i=0;i<s-1;i++){
val[lca(inds[i],inds[i+1])]-=2;
}
}
dfs(1,0);
sort(ans.begin(),ans.end());
cout<<ans.size()<<"\n";
for(int j:ans)cout<<j<<" ";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1756 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1756 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
2396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1756 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |