cf475B Strongly Connected City

时间:2022-09-22 10:11:49
B. Strongly Connected City
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.

The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

Input

The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets.

The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.

The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

Output

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

Sample test(s)
input
3 3
><>
v^v
output
NO
input
4 6
<><>
v^v^v^
output
YES
Note

The figure above shows street directions in the second sample test case.

sb模拟题

处理输入之后floyd乱搞

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
bool mark[500][500];
inline int g(int x,int y)
{
return (x-1)*m+y;
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
char ch=getchar();
while (ch!='>'&&ch!='<')ch=getchar();
for (int j=1;j<m;j++)
if (ch=='>') mark[g(i,j)][g(i,j+1)]=1;
else mark[g(i,j+1)][g(i,j)]=1;
}
for (int i=1;i<=m;i++)
{
char ch=getchar();
while (ch!='^'&&ch!='v')ch=getchar();
for (int j=2;j<=n;j++)
if (ch=='^') mark[g(j,i)][g(j-1,i)]=1;
else mark[g(j-1,i)][g(j,i)]=1;
}
int tot=n*m;
for(int k=1;k<=tot;k++)
for(int i=1;i<=tot;i++)
for (int j=1;j<=tot;j++)
mark[i][j]=mark[i][j]||(mark[i][k]&&mark[k][j]);
for (int i=1;i<=tot;i++)
for (int j=1;j<=tot;j++)
if (i!=j&&!mark[i][j])
{
printf("NO");
return 0;
}
printf("YES");
return 0;
}

  

cf475B Strongly Connected City的更多相关文章

  1. codeforces B&period; Strongly Connected City&lpar;dfs水过&rpar;

    题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向, 问是否每一个节点都可以由其他的节点到达.... 思路:规律没有想到,直接爆搜!每一个节点dfs ...

  2. Codeforces 475 B Strongly Connected City【DFS】

    题意:给出n行m列的十字路口,<代表从东向西,>从西向东,v从北向南,^从南向北,问在任意一个十字路口是否都能走到其他任意的十字路口 四个方向搜,搜完之后,判断每个点能够访问的点的数目是否 ...

  3. Codeforces-475B Strongly Connected City

    仅仅用推断最外层是不是回路  假设是   则每两个点之间连通 #include<iostream> #include<algorithm> #include<cstdio ...

  4. &lbrack;CF475E&rsqb;Strongly Connected City 2

    题目大意:给一张$n(n\leqslant2000)$个点的无向图,给所有边定向,使定向之后存在最多的有序点对$(a,b)$满足从$a$能到$b$ 题解:先把边双缩点,因为这里面的点一定两两可达. 根 ...

  5. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  6. algorithm&commat; Strongly Connected Component

    Strongly Connected Components A directed graph is strongly connected if there is a path between all ...

  7. Strongly connected&lpar;hdu4635(强连通分量)&rpar;

    /* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...

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

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

  9. HDU 4635 Strongly connected (Tarjan&plus;一点数学分析)

    Strongly connected Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

随机推荐

  1. &lbrack;MetaHook&rsqb; Surface hook

    Hook ISurface function. #include <metahook.h> #include <vgui/ISurface.h> using namespace ...

  2. FPS学习记录

    最近在网上查了一些FPS的相关知识,在此和大家一起分享.FPS(Frames Per Second):每秒传输帧数,它是图像领域中的一个术语. Frames Per Second更确切的解释是“每秒中 ...

  3. 总结与学习DIV&plus;CSS网页布局技巧

    以前用表格布局时设置网页居中非常方便,把表格对齐方式设置为居中就行了,就这么简单,现在呢,用DIV+CSS样式表控制,好像不是那么容易了,其实也很简单,只不过方式不同而已. <style> ...

  4. Java---设计模块&lpar;装饰模式&rpar;

    ★ 场景和问题 在不对原有对象类进行修改的基础上,如何给一个或多个已有的类对象提供增强额外的功能? ★ 引例 写一个MyBufferedReader类,使它能够对字符流(如FileReader.Inp ...

  5. 1&period; GDAL与OpenCV2&period;X数据转换(适合多光谱和高光谱等多通道的遥感影像)

    一.前言 GDAL具有强大的图像读写功能,但是对常用图像处理算法的集成较少,OpenCV恰恰具有较强的图像处理能力,因此有效的结合两者对图像(遥感影像)的处理带来了极大的方便.那么如何实现GDAL与o ...

  6. windows 下nginx 虚拟主机搭建

    需要在 nginx.conf里面引入刚才配置的那个文件   第一步 加东西 http的节点里面加上 一定要注意的是:必须以  ;  结尾 include D:/phpen/nginx-1.3.6/co ...

  7. 警惕32位程序在MethodImplOptions&period;Synchronized在x64机器上的同步缺陷&lbrack;z&rsqb;

    https://www.cnblogs.com/junchu25/archive/2012/08/10/2631422.html 上周四产品上线一切运行正常,做了一点小改动后周四晚上发布,周五大量用户 ...

  8. springboot整合elasticsearch入门例子

    springboot整合elasticsearch入门例子 https://blog.csdn.net/tianyaleixiaowu/article/details/72833940 Elastic ...

  9. 初次从eclipse转到intellij idea上的一些经验

    如果出现:mvn 请使用 -source 7 或更高版本以启用 diamond 运算符 这种问题 pom.xml里 <build>标签里面 需要加入这么一段 <plugins> ...

  10. EDK&lowbar;II环境搭建与测试

    一. 环境准备 Windows 10 (64位)专业版 Visual Studio 2010旗舰版(默认路径安装) Mscrosoft SDKs 7.0A BIOS综合包里的EDK开发环境 二. 实验 ...