cf796d 树,bfs好题!
绝对是好题,把所有警察局放入队列然后开始广搜,如果碰到了vis过的顶点,但是那条边没有访问过,那么这条边就可以删掉
另外广搜的vis标记是在入队时就打的,,
#include<bits/stdc++.h>
using namespace std;
#define maxn 300005 struct Edge{
int to,next,flag,id;
}edge[maxn<<];
int n,k,d,head[maxn],tot,p[maxn],vis[maxn]; void init(){
tot=;
memset(vis,,sizeof vis);
memset(head,-,sizeof head);
} void addedge(int u,int v,int id){
edge[tot].to=v;edge[tot].flag=;edge[tot].id=id;edge[tot].next=head[u];
head[u]=tot++;
} int main(){
int u,v;
init();
scanf("%d%d%d",&n,&k,&d);
for(int i=;i<=k;i++)scanf("%d",&p[i]);
for(int i=;i<n;i++){
scanf("%d%d",&u,&v);
addedge(u,v,i);addedge(v,u,i);
} queue<int> q;while(!q.empty())q.pop();
for(int i=;i<=k;i++)q.push(p[i]),vis[p[i]]=;
while(!q.empty()){
int u=q.front();q.pop();
//cout << u << '\n';
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
//cout << v << ' ';
if(vis[v] && !edge[i].flag){
edge[i].flag=edge[i^].flag=;
continue;
}
else if(!vis[v] && !edge[i].flag){
edge[i].flag=edge[i^].flag=;
vis[v]=;
q.push(v);
}
}
}
int ans=;
for(int i=;i<tot;i+=) if(edge[i].flag==) ans++;printf("%d\n",ans);
for(int i=;i<tot;i+=) if(edge[i].flag==) printf("%d ",edge[i].id);
return ;
}
cf796d 树,bfs好题!的更多相关文章
- hdu5325 树的思维题
pid=5325">http://acm.hdu.edu.cn/showproblem.php? pid=5325 Problem Description Bobo has a tre ...
- WOJ1024 (POJ1985+POJ2631) Exploration 树/BFS
title: WOJ1024 (POJ1985+POJ2631) Exploration 树/BFS date: 2020-03-20 10:43:00 categories: acm tags: [ ...
- HDU 4578 Transformation --线段树,好题
题意: 给一个序列,初始全为0,然后有4种操作: 1. 给区间[L,R]所有值+c 2.给区间[L,R]所有值乘c 3.设置区间[L,R]所有值为c 4.查询[L,R]的p次方和(1<=p< ...
- Hihicoder 题目1 : Trie树(字典树,经典题)
题目1 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编 ...
- poj 3264:Balanced Lineup(线段树,经典题)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 32820 Accepted: 15447 ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12731 Accepted: 544 ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- hdu 1251:统计难题(字典树,经典题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- JSONObject的toBean 和 fromObject
public static void main(String[] args) { Map map=new HashMap(); map.put("我","妹") ...
- js模块化的两种规范AMD和CMD
AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMDCMD 规范在这里:https://github.com/seajs/seajs/issues ...
- Linux命令之touch
touch命令 用处:新建文件 (默认是文本,你可以自己加后缀) 用法:在终端中输入touch加上要新建的文件的名字(注意!同一目录下文件夹和文件是不允许同名的) 示例: (新建一个名字叫newfil ...
- Linux 命令详解(九)轻易删除OpenSSL 的后果
警告自己,不要轻易的去删除系统的软件 1.composer自动更新出现错误 www@TinywanAliYun:~/web/go-study-line$ composer self-update Ke ...
- android 插件合集
1.增加编译速度:fastdex-plugin 2.gradle 版本网站http://services.gradle.org/distributions/
- Mongodb 副本集
mongodb主从模式就是一个 单副本的应用:没有很好的扩展性和容错性: 副本集的多个副本保证了容错性:主服务器负责整个副本集的读写,副本集定时同步数据:主节点挂掉:副本集会自动选举一个主的服务器: ...
- Python中str()和repr()函数的区别
在 Python 中要将某一类型的变量或者常量转换为字符串对象通常有两种方法,即 str() 或者 repr() . 区别与使用函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供 ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...
- python - 计算器 程序练习
v1.0 计算器(数据内不含括号方式:) import re def jisuan(a,b,c): sun_count = 0 if c =="+": sun_count = st ...
- SpringBoot2.X自定义拦截器实战及新旧配置对比(核心知识)
简介: 讲解拦截器使用,Spingboot2.x新版本配置拦截拦截器和旧版本SpringBoot配置拦截器区别讲解 1.@Configuration 继承WebMvcConfigurationAdap ...