This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;
int n, m, k, s[maxn], res[maxn], sz[maxn];
vector <pii> adj[maxn];
vector <int> col[maxn], ans;
map <int, int> cnt[maxn];
void relax(int v, int c, int x) {
if (cnt[v][c] == 0) res[v]++;
cnt[v][c] += x;
if (cnt[v][c] == s[c]) res[v]--;
}
void dfs(int v, int p, int ed) {
for (int c : col[v]) relax(v, c, 1);
sz[v] = col[v].size();
for (pii e : adj[v]) {
int u = e.F;
if (u == p) continue;
dfs(u, v, e.S);
if (sz[u] > sz[v]) {
res[v] = res[u];
swap(cnt[v], cnt[u]);
}
for (auto it = cnt[u].begin(); it != cnt[u].end(); it++) relax(v, it->F, it->S);
sz[v] += sz[u];
}
if (res[v] >= k) ans.pb(ed);
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i < n; i++) {
int v, u; cin >> v >> u;
adj[--v].pb(mp(--u, i));
adj[u].pb(mp(v, i));
}
for (int i = 0; i < m; i++) {
cin >> s[i];
for (int j = 0; j < s[i]; j++) {
int v; cin >> v;
col[--v].pb(i);
}
}
dfs(0, 0, 0);
sort(all(ans));
cout << ans.size() << '\n';
for (int i : ans) cout << i << ' ';
cout << '\n';
return 0;
}
# | 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... |