# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
952092 | Trisanu_Das | Railway (BOI17_railway) | C++17 | 159 ms | 39608 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;
const int Nmax = 1e5 + 10;
int n, m, k;
unordered_map <int, int> mp[Nmax];
vector <pair <int, int> > e[Nmax];
int s[Nmax];
vector <int> ans;
void dfs(int u, int p, int ide) {
for (auto [v, id]: e[u]) {
if (v == p) continue;
dfs(v, u, id);
if (mp[u].size() < mp[v].size()) mp[u].swap(mp[v]);
for (auto [i, x]: mp[v]) {
mp[u][i] += x;
if (mp[u][i] == s[i]) mp[u].erase(i);
}
}
if (mp[u].size() >= k) ans.push_back(ide);
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
e[u].push_back({v, i});
e[v].push_back({u, i});
}
for (int i = 1; i <= m; ++i) {
cin >> s[i];
for (int j = 1; j <= s[i]; ++j) {
int u;
cin >> u;
++mp[u][i];
}
}
dfs(1, 0, 0);
cout << ans.size() << '\n';
sort(ans.begin(), ans.end());
for (auto id: ans) cout << id << ' ';
}
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... |