#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define sz(v) (ll)(v.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.end()
#define f first
#define s second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
const ll sz = 1e5+5;
ll n, m, k, i, j;
vl g[sz];
ll vis[sz], cnt[sz];
map<ll, ll>mp[sz];
map<pll, ll>idx;
vl res;
void dfs(ll node, ll par = 0)
{
vis[node] = 1;
for(auto u : g[node])
{
if(vis[u])
continue;
dfs(u, node);
if(sz(mp[node]) < sz(mp[u]))
swap(mp[u], mp[node]);
for(auto h : mp[u])
{
mp[node][h.f] += h.s;
if(mp[node][h.f] == cnt[h.f])
mp[node].erase(h.f);
}
}
if(sz(mp[node]) >= k)
res.pb(idx[{node, par}]);
}
void solve()
{
cin >> n >> m >> k;
for(i = 1; i <= n - 1; i++)
{
ll x, y;
cin >> x >> y;
idx[{x, y}] = idx[{y, x}] = i;
g[x].pb(y);
g[y].pb(x);
}
for(i = 1; i <= m; i++)
{
ll s;
cin >> s;
for(j = 1; j <= s; j++)
{
ll x;
cin >> x;
mp[x][i]++;
}
cnt[i] = s;
}
dfs(1);
cout << sz(res) << "\n";
for(auto u : res)
cout << u << ' ';
cout << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
solve();
}
}
# | 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... |