796D Police Stations
来源:互联网 发布:阿里云 搭建vpn 编辑:程序博客网 时间:2024/06/03 16:08
#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;}
0 0
- 796D Police Stations
- Codeforces 796D Police Stations 构造+BFS
- Codeforces 796D Police Stations (bfs+思维)
- Codeforces Round #408 D. Police Stations
- D. Police Stations----多起点bfs
- Police Stations
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- Codeforces Round #408 (Div. 2) -- D. Police Stations(bfs)
- Codeforces Round #408 (Div. 2) D. Police Stations
- Codeforces Round #408 (Div. 2)-D. Police Stations
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- codeforces796D Police Stations
- Codeforces Round #408 (Div. 2) D. Police Stations 最短路、BFS
- Codeforces Round #408 (Div. 2)-D. Police Stations-多起点bfs
- Police Dog
- 解题报告:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations (DP)
- Servicing Stations
- uva10160Servicing Stations
- 二叉搜索树的后序遍历序列(Java实现)
- google play 排行榜接入
- 二维指针malloc和free
- JSON序列化
- SSIS 包配置
- 796D Police Stations
- 线程基础(一)
- POJ 2385 Apple Catching(线性DP)
- SpringMVC 过滤器HiddenHttpMethodFilter
- sysctl.conf学习和调优
- oracle两表关联更新
- 怎样做需求分析
- python dict转xml
- 使用springMVC的校验机制