This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ii = pair<int, int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
vector<vii> tree;
vi req;
vb connect;
bool dfs(int u, int p) {
bool ans = connect[u];
for (ii & e : tree[u]) {
if (e.second != p && dfs(e.second, u)) {
ans = true;
req[e.first]++;
}
}
return ans;
}
int main() {
int n, m, k; cin >> n >> m >> k;
tree.resize(n), req.resize(n - 1);
for (int i = 0; i < n - 1; ++i) {
int a, b; cin >> a >> b; a--; b--;
tree[a].emplace_back(i, b);
tree[b].emplace_back(i, a);
}
for (int i = 0; i < m; ++i) {
int s; cin >> s;
connect.assign(n, 0);
int c;
for (int j = 0; j < s; ++j) {
cin >> c; c--;
connect[c] = 1;
}
dfs(c, -1);
}
vi ans;
for (int i = 0; i < n - 1; ++i) {
if (req[i] >= k) ans.push_back(i + 1);
}
cout << ans.size() << endl;
for (int e : ans) cout << e << " ";
cout << endl;
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... |