Submission #924544

#TimeUsernameProblemLanguageResultExecution timeMemory
924544UmairAhmadMirzaRailway (BOI17_railway)C++17
23 / 100
69 ms81240 KiB
#include <bits/stdc++.h> using namespace std; int const N=10005; int const M=2005; vector<int> adj[N]; int cnt[N][M]; int sz[M]; vector<int> ans; int n,m,k; map<pair<int,int>,int> mp; void dfs(int node,int par){ for(auto i:adj[node]) if(i!=par){ dfs(i,node); for(int j=0;j<m;j++) cnt[node][j]+=cnt[i][j]; } int p=0; for(int j=0;j<m;j++) if(cnt[node][j]<sz[j] && cnt[node][j]>0) p++; if(p>=k && par!=-1) ans.push_back(mp[{par,node}]); } int main(){ 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][i]++; } } dfs(1,-1); cout<<ans.size()<<endl; sort(ans.begin(),ans.end()); for(auto i:ans) cout<<i<<' '; cout<<endl; return 0; }
#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...