吝啬的国度
来源:互联网 发布:java开发pc客户端 编辑:程序博客网 时间:2024/04/27 21:56
http://acm.nyist.net/JudgeOnline/problem.php?pid=20
#include <stdio.h>
#include <string.h>
int map[100005];
void DFS(int start)
{
int pre = map[start];
if (pre != 0)
{
DFS(pre);
map[pre] = start;
}
}
int main()
{
int m, n, start, a, b,i;
scanf("%d",&m);
while (m--)
{
scanf("%d%d",&n,&start);;
memset(map, 0, sizeof(map));
for (i = 1; i < n; i++)
{
scanf("%d%d",&a,&b);
if (map[b] == 0)
map[b] = a;
else
{
DFS(a);
map[a] = b;
}
}
DFS(start);
map[start] = -1;
for (i = 1; i < n; i++)
printf("%d ",map[i]);
printf("%d\n",map[n]);
}
return 0;
}
0 0
- nyoj_20 吝啬的国度
- 吝啬的国度
- noj 吝啬的国度
- 吝啬的国度
- NYOJ 吝啬的国度
- NYOJ 吝啬的国度
- 吝啬的国度
- nyoj20(吝啬的国度)
- 吝啬的国度
- 吝啬的国度
- 【搜索】吝啬的国度
- 吝啬的国度
- NY20 吝啬的国度
- NYOJ20-吝啬的国度
- 吝啬的国度
- 吝啬的国度
- 吝啬的国度
- 吝啬的国度 nyoj
- C#获取指定路径的所有文件
- Windows编译Ogre1.10
- python 生成项目模板 用于打包
- bzoj 2463 题解
- 使用JAXB 进行XML格式数据导入导出 Restful service
- 吝啬的国度
- redis的一些优化
- 2、跑马灯效果-获取网络图片并缓存到本地
- sass系列之css3-分裂规则
- SDJZU_新生_KMP/字符串
- python 解码 unicode 明文
- UIScrollView不能响应UITouch事件的解决办法
- pcduino v3安装ROS for hydro
- Oracle--触发器