ZOJ 2475 Benny's Compiler(DFS)
2013-05-09 19:27
399 查看
主要用的是dfs
注意如果 x 引用x 那么是可以的.
注意如果 x 引用x 那么是可以的.
#include <iostream> #include <cstdio> #include <memory.h> using namespace std; const int maxn = 110; int n, e; bool g[maxn][maxn], vis[maxn]; bool dfs(int u){ vis[u] = 1; for (int i = 1; i <= n; ++i){ if(g[u][i] && u != i){ if(vis[i])return false; else{ vis[i] = 1; if(!dfs(i)) return false; vis[i] = 0; } } } return true; } int main(){ while (scanf("%d", &n) && n > 0){ memset(vis, 0, sizeof(vis)); memset(g, false, sizeof(g)); for (int i = 0; i < n; ++i){ int u, v; scanf("%d %d", &u, &v); g[u][v] = 1; } scanf("%d", &e); if(dfs(e)){ printf("Yes\n"); }else{ printf("No\n"); } } return 0; }
相关文章推荐
- zoj 2475 Benny's Compiler
- zoj 2475 Benny's Compiler
- ZOJ 3631 Watashi's BG(DFS)
- 组队赛#1 解题总结 ZOJ 3803 YY's Minions (DFS搜索+模拟)
- ZOJ 2475 Benny's Compiler 有向图判读点是否存在环内
- ZOJ-#3631 Watashi's BG(DFS+剪枝)
- HDU 1045&ZOJ 1002 Fire Net (还是DFS呀...)
- ZOJ Problem Set - 2004 Commedia dell'arte
- pku 2488 A Knight's Journey (搜索 DFS)
- zoj 1738 - Lagrange's Four-Square Theorem
- ZOJ 3696 Alien's Organ(泊松分布)
- hdu 4274 Spy's Work DFS 贪心
- UVa 639 Don't Get Rooked (DFS好题)
- ZOJ 题目3587 Marlon's String(KMP)
- ZOJ 3811 dfs&并查集
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
- ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]
- POJ2965 The Pilots Brothers' refrigerator (精妙方法秒杀DFS BFS)
- hdu 1160 || zoj 1108 FatMouse's Speed
- POJ1041 John's trip(欧拉回路 + 并查集 + dfs)