제출 #695269

#제출 시각아이디문제언어결과실행 시간메모리
695269Ahmed_SolymanRailway (BOI17_railway)C++14
8 / 100
1089 ms30752 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); } vector<int>vis(n+5); map<pair<int,int>,int>e; vector<int>parent(n+5); while(m--){ int k;cin>>k; vector<int>v(k); for(auto &i:v)cin>>i; int root=v[0]; queue<int>q; q.push(root); for(int i=0;i<n;i++)vis[i+1]=0,parent[i+1]=0; while(q.size()){ int x=q.front(); q.pop(); vis[x]=1; for(auto i:adj[x]){ if(!vis[i]){ q.push(i); parent[i]=x; } } } map<pair<int,int>,bool>z; for(int i=1;i<k;i++){ int u=v[i]; while(u!=root){ z[{u,parent[u]}]=1; z[{parent[u],u}]=1; u=parent[u]; } } for(auto i:z){ //cout<<i.first.first<<" : "<<i.first.second<<endl; e[i.first]++; } } vector<int>d; for(int i=0;i<n-1;i++){ if(e[{a[i],b[i]}]>=k){ 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...