zoj 2475 Catenyms
2011-02-22 18:18
351 查看
DFS搜索。
开始以为是强连通分量,用tarjan套了半天模板不对 = =。。。
直接构图后,拿需要编译的编号为起点深搜即可,如果搜到的点标记过了,说明搜到环了,说明这个环不能被编译,以至于指向这个环的点都不能被编译。因为指向的点是变量在那个点里的。
一直WA,后来想到数据,1 1 1 1.这个应该输出Yes。。。改一下就好了。
开始以为是强连通分量,用tarjan套了半天模板不对 = =。。。
直接构图后,拿需要编译的编号为起点深搜即可,如果搜到的点标记过了,说明搜到环了,说明这个环不能被编译,以至于指向这个环的点都不能被编译。因为指向的点是变量在那个点里的。
一直WA,后来想到数据,1 1 1 1.这个应该输出Yes。。。改一下就好了。
#include <cstdio> #include <cstdlib> #include <iostream> #include <string.h> #include <queue> #include <stack> #include <math.h> #include <algorithm> #include <limits.h> #define MAX 101 using namespace std; int map[MAX][MAX]; int vis[MAX]; int ans,n; void init() { ans = 1; memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); } void DFS(int x) { int i; for(i=1; i<=n; i++) { if( vis[i] == 1 && map[x][i] ) { ans = 0; return ; } if( map[x][i] == 1 ) { vis[i] = 1; DFS(i); if( ans == 0 ) return ; vis[i] = 0; } } } int main() { int from,to,i,m; while( ~scanf("%d",&n) && n != -1 ) { init(); for(i=1; i<=n; i++) { scanf("%d%d",&from,&to); if( from != to ) map[from][to] = 1; } scanf("%d",&m); vis[m] = 1; DFS(m); if( ans ) printf("Yes/n"); else printf("No/n"); } return 0; }
相关文章推荐
- ZOJ1919 POJ2337 Catenyms,记录路径的欧拉图问题,同时路径是要按字典序输出
- POJ 2337 && ZOJ 1919--Catenyms 【有向图 && 欧拉路判断 && 欧拉路径】
- zoj 2475 Benny's Compiler
- zoj 2475 Benny's Compiler
- ZOJ 2475 Benny's Compiler(DFS)
- ZOJ 2475 dfs 少了一个条件WA了半天
- ZOJ-2475
- zoj 2475 Benny's Compiler
- ZOJ 2475 Benny's Compiler 有向图判读点是否存在环内
- zoj 2475 Benny's Compiler
- zoj 1919 || poj 2337 Catenyms
- zoj 1919 poj 2337 Catenyms(欧拉路径求解)
- zoj 3272 || hdu 3264 Open-air shopping malls(1Y哦~~哈哈哈哈~)
- ZOJ Goldbach 2013年长沙赛区网络赛
- ZOJ 1295: Reverse Text - cin.getline()
- ZOJ 3175 Number of Containers(n/1+n/2+...+n/(n-1)+n/n求法)
- zoj2711 Regular Words(DP)
- ZOJ - 2615 Cells
- POJ 1050/ ZOJ 1074:To the Max - DP求子矩阵和
- HDU 3783 ZOJ