#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()
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);
vll deg(n);
for(ll i = 0; i < n-1; ++i){
cin >> a >> b;
a--;b--;
g[a].insert({b,i+1});
g[b].insert({a,i+1});
deg[a]++;
deg[b]++;
}
vvl wh(n, vll(m));
vll am(n);
for(ll i = 0; i < m; ++i){
cin >> s;
while(s--){
cin >> a;a--;
am[a]++;
wh[a][i]=1;
}
}
vll ans;
queue<ll> pq;
for(ll i = 0; i < n; ++i)if(deg[i]==1)pq.push(i);
while(!pq.empty()){
ll i = pq.front();pq.pop();
if(g[i].empty())break;
pll e = *g[i].begin();
if(am[i]>=k){
ans.pb(e.s);
//am[e.f]=n;
}
for(ll j = 0; j < m; ++j){
if(wh[i][j] && !wh[e.f][j]){wh[e.f][j]=1;am[j]++;}
}
g[e.f].erase({i, e.s});
g[i].clear();
if(g[e.f].size()==1)pq.push(e.f);
}
cout << ans.size() << "\n";
for(ll i:ans)cout << i << " ";
}
# | 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... |