# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
606824 | Hanksburger | Railway (BOI17_railway) | C++17 | 219 ms | 34212 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;
vector<pair<int, int> > adj[100005];
map<int, int> mp[100005];
int s[100005], n, m, k;
vector<int> ans;
void dfs(int u, int p, int ind)
{
for (int i=0; i<adj[u].size(); i++)
{
int v=adj[u][i].first, w=adj[u][i].second;
if (v!=p)
{
dfs(v, u, w);
if (mp[u].size()<mp[v].size())
mp[u].swap(mp[v]);
for (auto itr=mp[v].begin(); itr!=mp[v].end(); itr++)
{
mp[u][itr->first]+=itr->second;
if (mp[u][itr->first]==s[itr->first])
mp[u].erase(itr->first);
}
}
}
if (mp[u].size()>=k)
ans.push_back(ind);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i=1; i<n; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back({v, i});
adj[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, 1, 0);
cout << ans.size() << '\n';
sort(ans.begin(), ans.end());
for (int i:ans)
cout << i << ' ';
return 0;
}
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... |