이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |