ZOJ 3332 Strange Country II
来源:互联网 发布:手机表格软件 编辑:程序博客网 时间:2024/05/07 20:07
题目大意:给你n*(n-1)条路线,代表可以从a走到b。
问你遍历所有点的路径输出。(可以输出任意解,每个城市只能走一次)
因为可以输出任意解,直接暴力搜索就好了。
#include <cstdio>#include <algorithm>#include <map>#include <cstring>#include <cmath>#include <iostream>using namespace std;#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1#define LL __int64typedef long long ll;#define PI 3.1415926int mat[150][150];int vis[150];int b[150];int n,l,flag;void dfs(int x){ int i; if(l==n) { flag=1; return; } for(i=1; i<=n; i++) { if(!vis[i]&&mat[x][i]) { b[l++]=i; vis[i]=1; dfs(i); if(flag==1) return; vis[i]=0; l--; } } return;}int main(){ int t,i; cin>>t; while(t--) { int a,c; cin>>n; if(n==1) { cout<<1<<endl; continue; } memset(b,0,sizeof(b)); memset(mat,0,sizeof(mat)); memset(vis,0,sizeof(vis)); for(i=1; i<=n*(n-1)/2; i++) { cin>>a>>c; mat[a][c]=1; } flag=0; for(i=1; i<=n; i++) { l=0; b[l++]=i; vis[i]=1; dfs(i); l--; if(flag) break; vis[i]=0; } if(flag) { for(i=0; i<n; i++) { if(i!=n-1) cout<<b[i]<<" "; else cout<<b[i]; } cout<<endl; } else cout<<"Impossible"<<endl; } return 0;}
0 0
- ZOJ 3332 Strange Country II
- zoj Strange Country II 3332
- ZOJ 3332 Strange Country II
- ZOJ 3332 Strange Country II
- zoj 3332 Strange Country II
- ZOJ 3332 Strange Country II
- ZOJ 3332 Strange Country II
- ZOJ 3332 Strange Country II暴力DFS
- zoj 3332-Strange Country II-dfs
- zoj 3332 Strange Country II (dfs)
- zoj 3332 Strange Country II DFS+回溯
- zoj 3332 Strange Country II (双塔dp)
- ZOJ 3332Strange Country II(图论)
- ZOJ 3332 Strange Country II【DFS】
- ZOJ 3332 Strange Country II 判断有向图联通
- ZOJ-3332-Strange Country II【7th浙江省赛】【dfs】
- ZOJ 3322 Strange Country II(DFS)
- ZOJ 3332 Strange Country II(竞赛图中的哈密顿路)
- 里氏替换原则
- 三场面试失败的总结
- [LeetCode]Longest Consecutive Sequence
- 深入理解 View 的事件传递机制
- 51单片机、STM32中生成QRCode二维码
- ZOJ 3332 Strange Country II
- Spring 3.x 各jar 包详解 与 依赖关系
- Apache Spark探秘:三种分布式部署方式比较
- 关于头文件中的理解
- ubuntu升级办法!
- 还是一个人安静想想人生吧
- j2ee部分jar包的作用
- POJ2413 How many Fibs?【高精度】【二分】
- [LeetCode]Next Permutation