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 main(){
int n,m,k;
cin>>n>>m>>k;
vector<int>adj[n+5];
vector<int>a(n+5),b(n+5);
for(int i=0;i<n-1;i++){
int u,v;cin>>u>>v;
a[i]=u;b[i]=v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int>vis(n+5);
map<pair<int,int>,int>e;
vector<int>parent(n+5);
while(m--){
int k;cin>>k;
vector<int>v(k);
for(auto &i:v)cin>>i;
int root=v[0];
queue<int>q;
q.push(root);
for(int i=0;i<n;i++)vis[i+1]=0,parent[i+1]=0;
while(q.size()){
int x=q.front();
q.pop();
vis[x]=1;
for(auto i:adj[x]){
if(!vis[i]){
q.push(i);
parent[i]=x;
}
}
}
map<pair<int,int>,bool>z;
for(int i=1;i<k;i++){
int u=v[i];
while(u!=root){
z[{u,parent[u]}]=1;
z[{parent[u],u}]=1;
u=parent[u];
}
}
for(auto i:z){
//cout<<i.first.first<<" : "<<i.first.second<<endl;
e[i.first]++;
}
}
vector<int>d;
for(int i=0;i<n-1;i++){
if(e[{a[i],b[i]}]>=k){
d.push_back(i+1);
}
}
cout<<d.size()<<endl;
for(auto i:d)cout<<i<<" ";
}
# | 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... |