PET
来源:互联网 发布:测井曲线解释软件 编辑:程序博客网 时间:2024/04/30 01:38
One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for three days. Nothing but cockroaches was caught. He got the map of the school and foundthat there is no cyclic path and every location in the school can be reached from his room. The trap’s manual mention that the pet will always come back if it still in somewhere nearer than distance D. Your task is to help Lin Ji to find out how many possible locations the hamster may found given the map of the school. Assume that the hamster is still hiding in somewhere in the school and distance between each adjacent locations is always one distance unit.
110 20 10 20 31 41 52 63 74 86 9
2
很好的 bfs
# include<iostream># include<cstdio># include<vector># include<queue># include<algorithm># define N 100010using namespace std;vector<int >e[N];int dis[N];bool vis[N];int main(){ int T; int i,n,d,a,b; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&d); for(i=0; i<=n; i++) { e[i].clear(); dis[i] = N; vis[i] = 0; } dis[0] = 0; for(i=1; i<n; i++) { scanf("%d%d",&a,&b); e[a].push_back(b); e[b].push_back(a); } queue<int >q; q.push(0); vis[0] = 1; while(!q.empty()) { int x = q.front(); q.pop(); for(i=0; i<e[x].size(); i++) { int y = e[x][i]; if(!vis[y]) { vis[y] = 1; dis[y] = dis[x] + 1; q.push(y); } } } int ans = 0; for(i=0; i<n; i++) if(dis[i] > d) ans ++; printf("%d\n",ans); } return 0;}
模仿 , 学习 , 。。。
阅读全文
0 0
- Pet
- Pet
- Pet
- Pet
- PET
- PET
- PET模型
- pet sqlhelper
- pet shop
- PET基础
- DOMText(pet)
- SBT(pet)
- hdu4707 Pet
- Pet类
- hd4707 Pet
- Pet--hdu4707
- hdu4707 Pet
- HDU4707 pet
- NOIP2017一条咸鱼的总结
- C++中this与*this的区别
- Python——注释
- hbase1.x的coprocessor应用
- qwtplot3d安装配置过程
- PET
- oracle使用小记:dblink、网闸及未设置密码
- 字符数组初始化书写格式
- ubuntu 16.04 安装opencv3.3
- seaborn可视化库分析库基础02
- opencv window 2411 依赖项
- 修复TortoiseGit文件夹和文件图标不显示问题
- 树莓派-wiringPi-优先级&中断&线程
- JAVA的CAS