PAT 1053 Path of Equal Weight DFS
来源:互联网 发布:hive 解决数据倾斜 编辑:程序博客网 时间:2024/05/22 12:45
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<vector>using namespace std;int a[105],fa[105];vector<int>v[105];int s;bool cmp(int x,int y){ return a[x]>a[y];}void out(int u){ vector<int>tp; while(u) { tp.push_back(u); u = fa[u]; } cout<<a[0]<<" "; for(int i = tp.size()-1;i>0;i--)cout<<a[tp[i]]<<" "; if(tp.size())cout<<a[tp[0]]<<endl;}void dfs(int u,int w){ if(w+a[u] == s&&v[u].size() == 0) { out(u); return; } if(w+a[u]>s)return; for(int i = 0;i<v[u].size();i++) { int t = v[u][i]; dfs(t,w+a[u]); }}int main(){ int n,m,i,j; scanf("%d%d%d",&n,&m,&s); memset(fa,-1,sizeof(fa)); for(i = 0;i<n;i++) { scanf("%d",&a[i]); } if(n == 1) { cout<<a[0]<<endl; return 0; } for(i = 1;i<=m;i++) { int u,t,nm; scanf("%d%d",&u,&nm); for(j = 1;j<=nm;j++) { scanf("%d",&t); v[u].push_back(t); fa[t] = u; } sort(v[u].begin(),v[u].end(),cmp); } dfs(0,0); return 0;}
0 0
- PAT 1053 Path of Equal Weight DFS
- PAT 1053 Path of Equal Weight
- 浙大PAT 1053题 1053. Path of Equal Weight
- 【PAT 1053】 Path of Equal Weight 深度优先搜索
- Pat(Advanced Level)Practice--1053(Path of Equal Weight)
- PAT (Advanced Level) Practise 1053 Path of Equal Weight (30)
- PAT (Advanced Level) Practise 1053 Path of Equal Weight (30)
- 1053. Path of Equal Weight (30)-PAT
- PAT 1053. Path of Equal Weight
- PAT 1053. Path of Equal Weight (30)
- PAT 1053. Path of Equal Weight (30)
- PAT 1053. Path of Equal Weight (30)
- 【PAT】1053. Path of Equal Weight (30)
- PAT 1042Path of Equal Weight (30)
- PAT 1053. Path of Equal Weight (30)
- PAT 1053. Path of Equal Weight
- PAT A1053. Path of Equal Weight (30)
- 【PAT】1053. Path of Equal Weight
- css+javascript特效:时钟(无图片纯div实现)
- XCode: An unknown error occurred.
- 顺序栈的常用操作
- 开发者必须mark的一款2D移动游戏开发工具
- 光盘yum源搭建步骤
- PAT 1053 Path of Equal Weight DFS
- Spring源代码解析(一):IOC容器:http://www.javaeye.com/topic/86339
- NHibernate使用手册(官网)
- EasyUI实现异步加载tree(整合Struts2)
- Vim插件管理利器——Vundle
- 姿势@_@ int long long 范围
- javaweb学习笔记:学习配置Tomcat7.0步骤
- PAT 1030 Travel Plan SPFA
- javax.servlet.ServletException: ClientAbortException: java.net.SocketException: Broken pipe错误完美解决