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;
int const N=10005;
int const M=2005;
vector<int> adj[N];
int cnt[N][M];
int sz[M];
vector<int> ans;
int n,m,k;
map<pair<int,int>,int> mp;
void dfs(int node,int par){
for(auto i:adj[node])
if(i!=par){
dfs(i,node);
for(int j=0;j<m;j++)
cnt[node][j]+=cnt[i][j];
}
int p=0;
for(int j=0;j<m;j++)
if(cnt[node][j]<sz[j] && cnt[node][j]>0)
p++;
if(p>=k && par!=-1)
ans.push_back(mp[{par,node}]);
}
int main(){
cin>>n>>m>>k;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
mp[{a,b}]=i+1;
mp[{b,a}]=i+1;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=0;i<m;i++){
cin>>sz[i];
for(int j=0;j<sz[i];j++){
int a;
cin>>a;
cnt[a][i]++;
}
}
dfs(1,-1);
cout<<ans.size()<<endl;
sort(ans.begin(),ans.end());
for(auto i:ans)
cout<<i<<' ';
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... |