Submission #695263

#TimeUsernameProblemLanguageResultExecution timeMemory
695263Ahmed_SolymanRailway (BOI17_railway)C++14
7 / 100
219 ms25232 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,k; cin>>n>>m>>k; vector<int>adj[n+5]; vector<int>a(n+5),b(n+5); for(int i=0;i<n-1;i++){ int u,v;cin>>u>>v; a[i]=u;b[i]=v; adj[u].push_back(v); adj[v].push_back(u); } int root; for(int i=1;i<=n;i++){ if(adj[i].size()==1){ root=i; } } queue<int>q; q.push(root); vector<bool>vis(n+5); vector<int>c; while(q.size()){ int x=q.front(); q.pop(); vis[x]=1; c.push_back(x); for(auto i:adj[x]){ if(!vis[i]){ q.push(i); } } } map<int,int>mp; for(int i=0;i<n;i++){ mp[c[i]]=i; } vector<int>p(n); while(m--){ int k;cin>>k; vector<int>v(k); for(auto &i:v)cin>>i; int l=1e9,r=-1; for(auto i:v){ l=min(l,mp[i]); r=max(r,mp[i]); } p[l]++; if(r+1<n){ p[r+1]--; } } map<pair<int,int>,bool>e; for(int i=1;i<n;i++){ p[i]+=p[i-1]; if(p[i]>=k && p[i-1]>=k){ e[{c[i],c[i-1]}]=1; e[{c[i-1],c[i]}]=1; } } vector<int>d; for(int i=0;i<n-1;i++){ if(e[{a[i],b[i]}]){ d.push_back(i+1); } } cout<<d.size()<<endl; for(auto i:d)cout<<i<<" "; }
#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...