#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
//--------------------------------------------------------------------
const ll N = 1e5 + 10;
ll st[N];
vector<ll> g[N];
ll timer;
ll n, m, k;
ll h[N], up[N][18];
void dfs(ll u, ll p) {
st[u] = ++timer;
for(auto v : g[u]) {
if(v == p) continue;
h[v] = h[u] + 1;
up[v][0] = u;
FOR(i, 1, 17) {
up[v][i] = up[up[v][i - 1]][i - 1];
}
dfs(v, u);
}
}
ll get(ll u, ll k) {
for(int j = 0; (1 << j) <= k; j++) {
if(bit(k, j)) u = up[u][j];
}
return u;
}
ll lca(ll u, ll v) {
if(h[u] < h[v]) swap(u, v);
u = get(u, h[u] - h[v]);
if(u == v) return u;
FORD(i, 17, 0) {
if(up[u][i] != up[v][i]) {
u = up[u][i];
v = up[v][i];
}
}
return up[u][0];
}
ll f[N];
vector<pa> g2[N];
ll b[N];
void dfs2(ll u, ll p) {
for(auto e : g2[u]) {
ll v = e.fi, id = e.se;
if(v == p) continue;
b[v] = id;
dfs2(v, u);
f[u] += f[v];
}
}
void hbmt() {
cin >> n >> m >> k;
FOR(i, 1, n - 1) {
ll u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
g2[u].push_back({v, i});
g2[v].push_back({u, i});
}
dfs(1, 0);
FOR(i, 1, m) {
ll s;
cin >> s;
vector<pa> vt;
FOR(j, 1, s) {
ll x;
cin >> x;
vt.push_back({st[x], x});
}
sort(vt.begin(), vt.end());
FOR(i, 0, vt.size() - 1) {
ll u = vt[i].se, v = vt[(i + 1) % vt.size()].se;
// cout << u << ' ' << v << ' ' << lca(u, v) << '\n';
f[lca(u, v)] += -2;
f[u] += 1;
f[v] += 1;
}
}
dfs2(1, 0);
vector<ll> vt;
FOR(i, 2, n) {
if(f[i] >= 2 * k) {
vt.push_back(b[i]);
}
}
sort(vt.begin(), vt.end());
cout << vt.size() << '\n';
for(auto e : vt) {
cout << e << ' ';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#define NAME "hbmt"
if(fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
//int t;cin>>t;while(t--)
hbmt();
return 0;
}
Compilation message (stderr)
railway.cpp: In function 'int main()':
railway.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
111 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |