#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
vector<map<ll,ll>> wh;
vll am, col;
void uni(ll a, ll b){
if(wh[a].size()<wh[b].size()){
uni(b,a);
swap(wh[a],wh[b]);
swap(am[a],am[b]);
return;
}
for(auto [c,d]:wh[b]){
if(d==0)continue;
if(!wh[a].count(c)){am[a]++;wh[a][c]=0;}
wh[a][c]+=d;
if(wh[a][c]==col[c])am[a]--;
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);
ll n, m, k, a ,b, s;
cin >> n >> m >> k;
vector<set<pll>> g(n);
for(ll i = 0; i < n-1; ++i){
cin >> a >> b;
a--;b--;
g[a].insert({b,i});
g[b].insert({a,i});
}
stack<ll> pq;
wh = vector<map<ll,ll>>(n);
am = vll(n);
col = vll(m);
for(ll i = 0; i < m; ++i){
cin >> s;
col[i]=s;
for(ll o = 0; o < s; ++o){
cin >> a;a--;
if(!wh[a].count(i)){am[a]++;wh[a][i]=0;}
wh[a][i]++;
if(wh[a][i]==col[i])am[a]--;
}
}
for(ll i = 0; i < n; ++i){
if(g[i].size()==1)pq.push(i);
}
vll ans;
while(!pq.empty()){
ll cr = pq.top();
pq.pop();
if(g[cr].size()!=1)break;
pll pr = *(g[cr].begin());
g[cr].clear();
g[pr.f].erase({cr, pr.s});
if(am[cr]>=k){
ans.pb(pr.s);
}
uni(pr.f, cr);
if(g[pr.f].size()==1)pq.push(pr.f);
}
cout << ans.size() << "\n";
for(ll i:ans)cout << 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... |