# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052625 | turska | Railway (BOI17_railway) | C++17 | 115 ms | 31248 KiB |
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;
#define all(v) (v).begin(), (v).end()
int n, m, k;
vector<pair<int, int>> adj[100001];
vector<int> q[100001];
int z[100001];
vector<int> ans;
map<int, int> dfs(int v, int p) {
map<int, int> a;
for (auto [u, i]: adj[v]) if (u!=p) {
map<int, int> b = dfs(u, v);
if (b.size()>=k) {
ans.push_back(i);
}
if (a.size() < b.size()) a.swap(b);
for (auto [k, v]: b) {
if (a[k]+v==z[k]) a.erase(k);
else a[k] += v;
}
}
for (auto u: q[v]) {
a[u]++;
if (a[u] == z[u]) a.erase(u);
}
return a;
}
int main() {
cin >> n >> m >> k;
for (int i=0; i<n-1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
for (int i=0; i<m; i++) {
int s;
cin >> s;
z[i] = s;
for (int j=0; j<s; j++) {
int k;
cin >> k;
q[k].push_back(i);
}
}
dfs(1, 1);
sort(all(ans));
cout << ans.size() << '\n';
for (auto i: ans) cout << i+1 << ' ';
}
Compilation message (stderr)
# | 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... |