题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向,
问是否每一个节点都可以由其他的节点到达....
思路:规律没有想到,直接爆搜!每一个节点dfs一次,记录每个节节点被访问的次数!如果每个节点最终的访问次数
和所有节点的数目相同,则输出“YES", 否则输出”NO“

 1 #include <queue>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <iostream>
 6 #include <algorithm>
 7
 8 using namespace std;
 9
10 char s1[25], s2[25];
11 int vis[25][25];
12 int cnt[25][25];
13 int n, m;
14
15 void dfs(int x, int y){
16     if(x<1 || x>n || y<1 || y>m || vis[x][y]) return;
17     ++cnt[x][y];
18     vis[x][y] = 1;
19     if(s1[x] == '<')
20         dfs(x, y-1);
21     else dfs(x, y+1);
22
23     if(s2[y] == 'v')
24         dfs(x+1, y);
25     else dfs(x-1, y);
26 }
27
28 int main(void)
29 {
30     scanf("%d%d", &n, &m);
31     scanf("%s%s", s1+1, s2+1);
32
33     for(int i=1; i<=n; ++i)
34         for(int j=1; j<=m; ++j){
35             memset(vis, 0, sizeof(vis));
36             dfs(i, j);
37         }
38     int s = n*m;
39     for(int i =1; i<=n; ++i)
40             for(int j=1; j<=m; ++j)
41                 if(cnt[i][j] != s){
42                     cout<<"NO"<<endl;
43                     return 0;
44                 }
45     cout<<"YES"<<endl;
46     return 0;
47 }

View Code

转载于:https://www.cnblogs.com/hujunzheng/p/4007917.html

codeforces B. Strongly Connected City(dfs水过)相关推荐

  1. CodeForces - 475B Strongly Connected City(最短路+判断强联通图/思维)

    题目链接:点击查看 题目大意:给出n和m然后给出n条横向街道和m条纵向街道,总共包括了n*m个结点,每条街道都是单向通道,问该图是否能够组成强联通图(有向图中任意两点间都存在路径) 题目分析:乍一看没 ...

  2. [CF475E]Strongly Connected City 2

    题意:给一个无向图,你需要给所有边定向,使定向之后存在最多的点对$(a,b)$使得从$a$能到$b$ 这个题,真的是太妙啦! 首先,给一个边双联通分量定向之后,它可以变成一个强联通分量,所以我们显然要 ...

  3. 强连通分量(SCC, Strongly Connected Components)

    强连通分量(SCC, Strongly Connected Component) 强连通分量的概念 强连通分量的应用 强连通分量的算法--Tarjan算法 强连通分量的概念 在有向图中,任意两个顶点 ...

  4. Tarjan's strongly connected components algorithm的一些想法

    Tarjan的极大强连通子图(strongly connected components,SCC)算法基于深度优先遍历(DFS)实现.本文就尝试从深度优先遍历的角度思考一下Tarjan的方法是如何找出 ...

  5. 强连通分量(strongly connected components)

    强连通分量(strongly connected components)    徐不可说        2018/8/4                                        ...

  6. FDS-HW11 6-1 Strongly Connected Components

    Strongly Connected Components 堆栈C语言实现:https://www.cnblogs.com/tingshuo123/p/7090858.html 思路分析 使用tarj ...

  7. HDU 4635 Strongly connected(缩点、最多可加边数使得仍然非强连通)

    整理的算法模板合集: ACM模板 HDU 4635 Strongly connected Give a simple directed graph with N nodes and M edges. ...

  8. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  9. 【CF913F】Strongly Connected Tournament 概率神题

    [CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...

最新文章

  1. 虚拟货币市值回调到4100亿整数关口,EOS逆势站上100关口
  2. Android Treble 计划技术文档
  3. 7.13. parallel - build and execute shell command lines from standard input in parallel
  4. 内存不足:杀死进程还是牺牲子进程
  5. dropload.min.js 下拉刷新后,无法上拉加载更多
  6. 让这家有12万名员工、1.7万种产品的钢铁厂平滑上云的黑科技是什么?
  7. php限制下载文件格式,php下载文件源代码(强制任意文件格式下载)_PHP教程
  8. 解决:Win10 程序切换/系统提示弹窗不在顶层
  9. 旷视天元开源图片对比工具 MegSpot,助力图像算法研发
  10. 三、Logstash安装部署
  11. JAVA文件下载,IE不提示下载,直接打开的解决方法
  12. 旅游路线定制APP开发是否具备发展前景呢?
  13. Linux进程的后台运行
  14. 基于 Fortran QuickWin 的物性计算应用程序开发示例
  15. Logic Pro X自带音色库列表
  16. 这次,认真搞了个外包兼职搞钱群!
  17. 如何进行Modbus 通讯测试
  18. Key Points Estimation and Point Instance
  19. vue简单购物车案例
  20. php五秒盾,typecho引入php五秒盾,实现自由配置

热门文章

  1. bert 多义词_自然语言处理:Bert及其他
  2. CentOS 7.8使用devtoolset-9使用高版本gcc version 9.3.1
  3. 安装和使用Ant Design Vue 图标库
  4. 数据加载约定表模型变更_08
  5. Centos7 使用Docker 部署Tomca+mysql+调试联通_02
  6. java镂空图案,我想打印镂空的菱形
  7. 同步fifo的串并_同步FIFO设计Spec(示例代码)
  8. 设置 Visual Studio 文件版权信息 - C语言零基础入门教程
  9. Python chr / ord 函数区别和使用 - Python零基础入门教程
  10. 搜索引擎排序DEMO