#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
int n, k, d;
while (cin >> n >> k >> d){
vector<int> police(k + 1);
vector<bool> visit(n + 1, false);
vector<int> remove(n);
int result = 0;
for (int i = 1; i <= k; i++){
cin >> police[i];
}
vector<vector<pair<int, int>>> way(n + 1, vector<pair<int, int>>());
for (int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
pair<int, int> temp;
temp.second = i;
temp.first = v;
way[u].push_back(temp);
temp.first = u;
way[v].push_back(temp);
}
queue<pair<int, int>> q;
for (int i = 1; i <= k; i++){
pair<int, int> temp;
temp.first = police[i];
temp.second = 0;
q.push(temp);
}
while (!q.empty()){
pair<int, int> t = q.front();
q.pop();
int index = t.first;
int from = t.second;
if (visit[index]) continue;
visit[index] = 1;
for (int i = 0; i < way[index].size(); i++){
pair<int, int> temp = way[index][i];
if (temp.first != from){
if (visit[temp.first]) remove[temp.second] = 1;
else{
pair<int, int> temp1;
temp1.first = temp.first;
temp1.second = index;
q.push(temp1);
}
}
}
}
for (int i = 1; i < n; i++){
if (remove[i]) result++;
}
cout << result << endl;
for (int i = 1; i < n; i++){
if (remove[i]) cout << i << " ";
}
cout << endl;
}
return 0;
}
796D Police Stations
最新推荐文章于 2021-06-19 21:19:02 发布