Submission #244642

#TimeUsernameProblemLanguageResultExecution timeMemory
244642santaclaus03Railway (BOI17_railway)C++14
23 / 100
1096 ms11000 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...