Submission #638067

#TimeUsernameProblemLanguageResultExecution timeMemory
638067ojoConmigoRailway (BOI17_railway)C++17
23 / 100
1082 ms15140 KiB
#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 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...