fork(9) download
  1. #include <stdio.h>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. queue<pair<int, int>> q;
  7. vector<pair<int, int>> way[300005];
  8. int v[300005];
  9. int res[300005];
  10.  
  11. int main(){
  12. int n, k, d;
  13. scanf("%d%d%d", &n, &k, &d);
  14. for(int i=0; i<k; i++){
  15. int p;
  16. scanf("%d", &p);
  17. q.push({p, 0});
  18. }
  19. for(int i=0; i<n-1; i++){
  20. int u, v;
  21. scanf("%d%d", &u, &v);
  22. way[u].push_back({v, i+1});
  23. way[v].push_back({u, i+1});
  24. }
  25. while(!q.empty()){
  26. int pos = q.front().first;
  27. int from = q.front().second;
  28. q.pop();
  29. if(v[pos]) continue;
  30. v[pos] = 1;
  31. for(int i=0; i<way[pos].size(); i++) if(way[pos][i].first != from){
  32. if(v[way[pos][i].first]) res[way[pos][i].second] = 1;
  33. else q.push({way[pos][i].first, pos});
  34. }
  35. }
  36. int rescnt=0;
  37. for(int i=1; i<=n-1; i++) if(res[i]) rescnt++;
  38. printf("%d\n", rescnt);
  39. for(int i=1; i<=n-1; i++) if(res[i]) printf("%d ", i);
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 25360KB
stdin
Standard input is empty
stdout
0