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=100005;
int const M=50005;
vector<int> adj[N];
vector<int> cnt[N];
int sz[M];
vector<int> ans;
int n,m,k;
map<pair<int,int>,int> mp;
multiset<int> minister;
void dfs(int node,int par){
for(auto i:adj[node])
if(i!=par)
dfs(i,node);
for(auto j:cnt[node])
minister.insert(j);
int p=0;
for(int j=0;j<m;j++){
int c=minister.count(j);
if(c<sz[j] && c>0)
p++;
}
if(p>=k && par!=-1)
ans.push_back(mp[{par,node}]);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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].push_back(i);
}
}
for(int i=1;i<=n;i++){
if(adj[i].size()>1)
continue;
dfs(i,-1);
break;
}
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... |