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<vector<pair<int,int>>> g;
vector<int> ask;
bool dfs(int nodo, int p, set<int> & vecindarios){
bool b = false;
if(vecindarios.find(nodo) != vecindarios.end()){
b = true;
vecindarios.erase(nodo);
if(vecindarios.empty()) return true;
}
for(auto pareja : g[nodo]){
int v = pareja.first;
if(v == p)continue;
int ind = pareja.second;
if(dfs(v,nodo,vecindarios)){
b = true;
ask[ind]++;
}
}
return b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m,k;
cin >> n >> m >> k;
//vector<pair<int,int>> tracks(n-1);
g.resize(n);
for(int i=0; i<n-1; i++){
int a,b;
cin >> a >> b;
a--;b--;
//tracks[i] = {a,b};
g[a].emplace_back(b,i);
g[b].emplace_back(a,i);
}
ask.assign(n-1,0);
for(int i=0; i<m; i++){
int len;
cin >> len;
set<int> vecindarios;
int x;
for(int j=0; j<len; j++){
cin >> x;
x--;
vecindarios.insert(x);
}
//dfs
vecindarios.erase(x);
dfs(x,-1,vecindarios);
}
vector<int> ans;
for(int i=0; i<n-1; i++){
if(ask[i] < k)continue;
ans.push_back(i);
}
cout << ans.size() << endl;
for(int x : ans){
cout << x+1 << " ";
}
cout << endl;
}
# | 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... |