제출 #924555

#제출 시각아이디문제언어결과실행 시간메모리
924555UmairAhmadMirzaRailway (BOI17_railway)C++17
0 / 100
1036 ms34128 KiB
#include <bits/stdc++.h> using namespace std; int const N=100005; int const M=50005; vector<int> adj[N]; vector<int> cnt[N]; int sz[M]; vector<int> ans; int n,m,k; map<pair<int,int>,int> mp; multiset<int> minister; void dfs(int node,int par){ for(auto i:adj[node]) if(i!=par) dfs(i,node); for(auto j:cnt[node]) minister.insert(j); int p=0; for(int j=0;j<m;j++){ int c=minister.count(j); if(c<sz[j] && c>0) p++; } if(p>=k && par!=-1) ans.push_back(mp[{par,node}]); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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].push_back(i); } } for(int i=1;i<=n;i++){ if(adj[i].size()>1) continue; dfs(i,-1); break; } 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...