Submission #638071

#TimeUsernameProblemLanguageResultExecution timeMemory
638071ojoConmigoRailway (BOI17_railway)C++17
23 / 100
1085 ms14020 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int>>> g; vector<int> ask; bool dfs(int nodo, int p, vector<bool> & vecindarios){ bool b = false; //if(vecindarios.find(nodo) != vecindarios.end()){ if(vecindarios[nodo]){ b = true; vecindarios[nodo] = false; auto cont = count(vecindarios.begin(),vecindarios.end(),true); if(!cont)return 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; vector<bool> vecindarios(n,false); int x; for(int j=0; j<len; j++){ cin >> x; x--; vecindarios[x] = true; //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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...